UNPKG

bytesforce-form-render

Version:

通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成

53 lines (45 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = html; var _react = _interopRequireDefault(require("react")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } function html(_ref) { var value = _ref.value, _ref$schema = _ref.schema, schema = _ref$schema === void 0 ? {} : _ref$schema; var __html = '-'; if (schema.type === 'boolean') { __html = value === true ? '✔' : '✘'; } else if (Array.isArray(schema.enum) && Array.isArray(schema.enumNames)) { if (['string', 'number'].indexOf(_typeof(value)) > -1) { var idx = schema.enum.indexOf(value); __html = schema.enumNames[idx] || '-'; } else if (Array.isArray(value)) { var idxStr = '-'; value.forEach(function (v) { var idx = schema.enum.indexOf(v); var name = schema.enumNames[idx]; if (name) { idxStr += ',' + name; } }); __html = idxStr.replace('-,', ''); } } else if (typeof value === 'number') { __html = String(value); } else if (typeof value === 'string') { __html = value; } else if (schema.type === 'range' && Array.isArray(value) && value[0] && value[1]) { __html = "".concat(value[0], " - ").concat(value[1]); } else if (value && ['number', 'string'].indexOf(value) === -1) { __html = JSON.stringify(value); } return /*#__PURE__*/_react.default.createElement("div", { dangerouslySetInnerHTML: { __html: __html } }); }