init
This commit is contained in:
@ -18,6 +18,7 @@
|
|||||||
"@element-plus/icons-vue": "2.0.10",
|
"@element-plus/icons-vue": "2.0.10",
|
||||||
"@vueuse/core": "9.5.0",
|
"@vueuse/core": "9.5.0",
|
||||||
"axios": "0.27.2",
|
"axios": "0.27.2",
|
||||||
|
"clipboard": "^2.0.11",
|
||||||
"echarts": "5.4.0",
|
"echarts": "5.4.0",
|
||||||
"element-plus": "2.2.21",
|
"element-plus": "2.2.21",
|
||||||
"file-saver": "2.0.5",
|
"file-saver": "2.0.5",
|
||||||
@ -26,12 +27,17 @@
|
|||||||
"jsencrypt": "3.3.1",
|
"jsencrypt": "3.3.1",
|
||||||
"nprogress": "0.2.0",
|
"nprogress": "0.2.0",
|
||||||
"pinia": "2.0.22",
|
"pinia": "2.0.22",
|
||||||
|
"throttle-debounce": "^5.0.0",
|
||||||
"vue": "3.2.45",
|
"vue": "3.2.45",
|
||||||
"vue-cropper": "1.0.3",
|
"vue-cropper": "1.0.3",
|
||||||
"vue-router": "4.1.4"
|
"vue-router": "4.1.4",
|
||||||
|
"vuedraggable": "^4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/parser": "^7.20.5",
|
||||||
"@vitejs/plugin-vue": "3.1.0",
|
"@vitejs/plugin-vue": "3.1.0",
|
||||||
|
"@vitejs/plugin-vue-jsx": "^3.0.0",
|
||||||
|
"@vue/babel-helper-vue-transform-on": "^1.0.2",
|
||||||
"@vue/compiler-sfc": "3.2.45",
|
"@vue/compiler-sfc": "3.2.45",
|
||||||
"sass": "1.56.1",
|
"sass": "1.56.1",
|
||||||
"unplugin-auto-import": "0.11.4",
|
"unplugin-auto-import": "0.11.4",
|
||||||
|
|||||||
2816
pnpm-lock.yaml
generated
Normal file
2816
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
54
src/utils/db.js
Normal file
54
src/utils/db.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
const DRAWING_ITEMS = 'drawingItems'
|
||||||
|
const DRAWING_ITEMS_VERSION = '1.2'
|
||||||
|
const DRAWING_ITEMS_VERSION_KEY = 'DRAWING_ITEMS_VERSION'
|
||||||
|
const DRAWING_ID = 'idGlobal'
|
||||||
|
const TREE_NODE_ID = 'treeNodeId'
|
||||||
|
const FORM_CONF = 'formConf'
|
||||||
|
|
||||||
|
export function getDrawingList() {
|
||||||
|
// 加入缓存版本的概念,保证缓存数据与程序匹配
|
||||||
|
const version = localStorage.getItem(DRAWING_ITEMS_VERSION_KEY)
|
||||||
|
if (version !== DRAWING_ITEMS_VERSION) {
|
||||||
|
localStorage.setItem(DRAWING_ITEMS_VERSION_KEY, DRAWING_ITEMS_VERSION)
|
||||||
|
saveDrawingList([])
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const str = localStorage.getItem(DRAWING_ITEMS)
|
||||||
|
if (str) return JSON.parse(str)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveDrawingList(list) {
|
||||||
|
localStorage.setItem(DRAWING_ITEMS, JSON.stringify(list))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getIdGlobal() {
|
||||||
|
const str = localStorage.getItem(DRAWING_ID)
|
||||||
|
if (str) return parseInt(str, 10)
|
||||||
|
return 100
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveIdGlobal(id) {
|
||||||
|
localStorage.setItem(DRAWING_ID, `${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTreeNodeId() {
|
||||||
|
const str = localStorage.getItem(TREE_NODE_ID)
|
||||||
|
if (str) return parseInt(str, 10)
|
||||||
|
return 100
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveTreeNodeId(id) {
|
||||||
|
localStorage.setItem(TREE_NODE_ID, `${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFormConf() {
|
||||||
|
const str = localStorage.getItem(FORM_CONF)
|
||||||
|
if (str) return JSON.parse(str)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveFormConf(obj) {
|
||||||
|
localStorage.setItem(FORM_CONF, JSON.stringify(obj))
|
||||||
|
}
|
||||||
651
src/utils/generator/config.js
Normal file
651
src/utils/generator/config.js
Normal file
@ -0,0 +1,651 @@
|
|||||||
|
// 表单属性【右面板】
|
||||||
|
export const formConf = {
|
||||||
|
formRef: "elForm",
|
||||||
|
formModel: "formData",
|
||||||
|
size: "default",
|
||||||
|
labelPosition: "right",
|
||||||
|
labelWidth: 100,
|
||||||
|
test1: 123,
|
||||||
|
formRules: "rules",
|
||||||
|
gutter: 15,
|
||||||
|
disabled: false,
|
||||||
|
span: 24,
|
||||||
|
formBtns: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 输入型组件 【左面板】
|
||||||
|
export const inputComponents = [
|
||||||
|
{
|
||||||
|
// 组件的自定义配置
|
||||||
|
__config__: {
|
||||||
|
label: "单行文本",
|
||||||
|
labelWidth: null,
|
||||||
|
showLabel: true,
|
||||||
|
changeTag: true,
|
||||||
|
tag: "el-input",
|
||||||
|
tagIcon: "input",
|
||||||
|
defaultValue: undefined,
|
||||||
|
required: true,
|
||||||
|
layout: "colFormItem",
|
||||||
|
span: 24,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/input",
|
||||||
|
// 正则校验规则
|
||||||
|
regList: [],
|
||||||
|
},
|
||||||
|
// 组件的插槽属性
|
||||||
|
__slot__: {
|
||||||
|
prepend: "",
|
||||||
|
append: "",
|
||||||
|
},
|
||||||
|
// 其余的为可直接写在组件标签上的属性
|
||||||
|
placeholder: "请输入",
|
||||||
|
style: { width: "100%" },
|
||||||
|
clearable: true,
|
||||||
|
"prefix-icon": "",
|
||||||
|
"suffix-icon": "",
|
||||||
|
maxlength: null,
|
||||||
|
"show-word-limit": false,
|
||||||
|
readonly: false,
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "多行文本",
|
||||||
|
labelWidth: null,
|
||||||
|
showLabel: true,
|
||||||
|
tag: "el-input",
|
||||||
|
tagIcon: "textarea",
|
||||||
|
defaultValue: undefined,
|
||||||
|
required: true,
|
||||||
|
layout: "colFormItem",
|
||||||
|
span: 24,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/input",
|
||||||
|
},
|
||||||
|
type: "textarea",
|
||||||
|
placeholder: "请输入",
|
||||||
|
autosize: {
|
||||||
|
minRows: 4,
|
||||||
|
maxRows: 4,
|
||||||
|
},
|
||||||
|
style: { width: "100%" },
|
||||||
|
maxlength: null,
|
||||||
|
"show-word-limit": false,
|
||||||
|
readonly: false,
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "密码",
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
changeTag: true,
|
||||||
|
tag: "el-input",
|
||||||
|
tagIcon: "password",
|
||||||
|
defaultValue: undefined,
|
||||||
|
layout: "colFormItem",
|
||||||
|
span: 24,
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
document: "https://element-plus.org/zh-CN/component/input",
|
||||||
|
},
|
||||||
|
__slot__: {
|
||||||
|
prepend: "",
|
||||||
|
append: "",
|
||||||
|
},
|
||||||
|
placeholder: "请输入",
|
||||||
|
"show-password": true,
|
||||||
|
style: { width: "100%" },
|
||||||
|
clearable: true,
|
||||||
|
"prefix-icon": "",
|
||||||
|
"suffix-icon": "",
|
||||||
|
maxlength: null,
|
||||||
|
"show-word-limit": false,
|
||||||
|
readonly: false,
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "计数器",
|
||||||
|
showLabel: true,
|
||||||
|
changeTag: true,
|
||||||
|
labelWidth: null,
|
||||||
|
tag: "el-input-number",
|
||||||
|
tagIcon: "number",
|
||||||
|
defaultValue: undefined,
|
||||||
|
span: 24,
|
||||||
|
layout: "colFormItem",
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
document: "https://element-plus.org/zh-CN/component/input-number",
|
||||||
|
},
|
||||||
|
placeholder: "",
|
||||||
|
min: undefined,
|
||||||
|
max: undefined,
|
||||||
|
step: 1,
|
||||||
|
"step-strictly": false,
|
||||||
|
precision: undefined,
|
||||||
|
"controls-position": "",
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "编辑器",
|
||||||
|
showLabel: true,
|
||||||
|
changeTag: true,
|
||||||
|
labelWidth: null,
|
||||||
|
tag: "tinymce",
|
||||||
|
tagIcon: "rich-text",
|
||||||
|
defaultValue: null,
|
||||||
|
span: 24,
|
||||||
|
layout: "colFormItem",
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
document: "http://tinymce.ax-z.cn",
|
||||||
|
},
|
||||||
|
placeholder: "请输入",
|
||||||
|
height: 300, // 编辑器高度
|
||||||
|
branding: false, // 隐藏右下角品牌烙印
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 选择型组件 【左面板】
|
||||||
|
export const selectComponents = [
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "下拉选择",
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
tag: "el-select",
|
||||||
|
tagIcon: "select",
|
||||||
|
layout: "colFormItem",
|
||||||
|
span: 24,
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/select",
|
||||||
|
},
|
||||||
|
__slot__: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: "选项一",
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "选项二",
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
placeholder: "请选择",
|
||||||
|
style: { width: "100%" },
|
||||||
|
clearable: true,
|
||||||
|
disabled: false,
|
||||||
|
filterable: false,
|
||||||
|
multiple: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "级联选择",
|
||||||
|
url: "https://www.fastmock.site/mock/f8d7a54fb1e60561e2f720d5a810009d/fg/cascaderList",
|
||||||
|
method: "get",
|
||||||
|
dataKey: "list",
|
||||||
|
dataConsumer: "options",
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
tag: "el-cascader",
|
||||||
|
tagIcon: "cascader",
|
||||||
|
layout: "colFormItem",
|
||||||
|
defaultValue: [],
|
||||||
|
dataType: "dynamic",
|
||||||
|
span: 24,
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/cascader",
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
value: 1,
|
||||||
|
label: "选项1",
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
value: 2,
|
||||||
|
label: "选项1-1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
placeholder: "请选择",
|
||||||
|
style: { width: "100%" },
|
||||||
|
props: {
|
||||||
|
props: {
|
||||||
|
multiple: false,
|
||||||
|
label: "label",
|
||||||
|
value: "value",
|
||||||
|
children: "children",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"show-all-levels": true,
|
||||||
|
disabled: false,
|
||||||
|
clearable: true,
|
||||||
|
filterable: false,
|
||||||
|
separator: "/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "单选框组",
|
||||||
|
labelWidth: null,
|
||||||
|
showLabel: true,
|
||||||
|
tag: "el-radio-group",
|
||||||
|
tagIcon: "radio",
|
||||||
|
changeTag: true,
|
||||||
|
defaultValue: undefined,
|
||||||
|
layout: "colFormItem",
|
||||||
|
span: 24,
|
||||||
|
optionType: "default",
|
||||||
|
regList: [],
|
||||||
|
required: true,
|
||||||
|
border: false,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/radio",
|
||||||
|
},
|
||||||
|
__slot__: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: "选项一",
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "选项二",
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
style: {},
|
||||||
|
size: "default",
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "多选框组",
|
||||||
|
tag: "el-checkbox-group",
|
||||||
|
tagIcon: "checkbox",
|
||||||
|
defaultValue: [],
|
||||||
|
span: 24,
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
layout: "colFormItem",
|
||||||
|
optionType: "default",
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
border: false,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/checkbox",
|
||||||
|
},
|
||||||
|
__slot__: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: "选项一",
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "选项二",
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
style: {},
|
||||||
|
size: "default",
|
||||||
|
min: null,
|
||||||
|
max: null,
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "开关",
|
||||||
|
tag: "el-switch",
|
||||||
|
tagIcon: "switch",
|
||||||
|
defaultValue: false,
|
||||||
|
span: 24,
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
layout: "colFormItem",
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/switch",
|
||||||
|
},
|
||||||
|
style: {},
|
||||||
|
disabled: false,
|
||||||
|
"active-text": "",
|
||||||
|
"inactive-text": "",
|
||||||
|
"active-color": null,
|
||||||
|
"inactive-color": null,
|
||||||
|
"active-value": true,
|
||||||
|
"inactive-value": false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "滑块",
|
||||||
|
tag: "el-slider",
|
||||||
|
tagIcon: "slider",
|
||||||
|
defaultValue: null,
|
||||||
|
span: 24,
|
||||||
|
showLabel: true,
|
||||||
|
layout: "colFormItem",
|
||||||
|
labelWidth: null,
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/slider",
|
||||||
|
},
|
||||||
|
disabled: false,
|
||||||
|
min: 0,
|
||||||
|
max: 100,
|
||||||
|
step: 1,
|
||||||
|
"show-stops": false,
|
||||||
|
range: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "时间选择",
|
||||||
|
tag: "el-time-picker",
|
||||||
|
tagIcon: "time",
|
||||||
|
defaultValue: null,
|
||||||
|
span: 24,
|
||||||
|
showLabel: true,
|
||||||
|
layout: "colFormItem",
|
||||||
|
labelWidth: null,
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/time-picker",
|
||||||
|
},
|
||||||
|
placeholder: "请选择",
|
||||||
|
style: { width: "100%" },
|
||||||
|
disabled: false,
|
||||||
|
clearable: true,
|
||||||
|
"picker-options": {
|
||||||
|
selectableRange: "00:00:00-23:59:59",
|
||||||
|
},
|
||||||
|
format: "HH:mm:ss",
|
||||||
|
"value-format": "HH:mm:ss",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "时间范围",
|
||||||
|
tag: "el-time-picker",
|
||||||
|
tagIcon: "time-range",
|
||||||
|
span: 24,
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
layout: "colFormItem",
|
||||||
|
defaultValue: null,
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/time-picker",
|
||||||
|
},
|
||||||
|
style: { width: "100%" },
|
||||||
|
disabled: false,
|
||||||
|
clearable: true,
|
||||||
|
"is-range": true,
|
||||||
|
"range-separator": "至",
|
||||||
|
"start-placeholder": "开始时间",
|
||||||
|
"end-placeholder": "结束时间",
|
||||||
|
format: "HH:mm:ss",
|
||||||
|
"value-format": "HH:mm:ss",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "日期选择",
|
||||||
|
tag: "el-date-picker",
|
||||||
|
tagIcon: "date",
|
||||||
|
defaultValue: null,
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
span: 24,
|
||||||
|
layout: "colFormItem",
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/date-picker",
|
||||||
|
},
|
||||||
|
placeholder: "请选择",
|
||||||
|
type: "date",
|
||||||
|
style: { width: "100%" },
|
||||||
|
disabled: false,
|
||||||
|
clearable: true,
|
||||||
|
format: "yyyy-MM-dd",
|
||||||
|
"value-format": "yyyy-MM-dd",
|
||||||
|
readonly: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "日期范围",
|
||||||
|
tag: "el-date-picker",
|
||||||
|
tagIcon: "date-range",
|
||||||
|
defaultValue: null,
|
||||||
|
span: 24,
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
required: true,
|
||||||
|
layout: "colFormItem",
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/date-picker",
|
||||||
|
},
|
||||||
|
style: { width: "100%" },
|
||||||
|
type: "daterange",
|
||||||
|
"range-separator": "至",
|
||||||
|
"start-placeholder": "开始日期",
|
||||||
|
"end-placeholder": "结束日期",
|
||||||
|
disabled: false,
|
||||||
|
clearable: true,
|
||||||
|
format: "yyyy-MM-dd",
|
||||||
|
"value-format": "yyyy-MM-dd",
|
||||||
|
readonly: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "评分",
|
||||||
|
tag: "el-rate",
|
||||||
|
tagIcon: "rate",
|
||||||
|
defaultValue: 0,
|
||||||
|
span: 24,
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
layout: "colFormItem",
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/rate",
|
||||||
|
},
|
||||||
|
style: {},
|
||||||
|
max: 5,
|
||||||
|
"allow-half": false,
|
||||||
|
"show-text": false,
|
||||||
|
"show-score": false,
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "颜色选择",
|
||||||
|
tag: "el-color-picker",
|
||||||
|
tagIcon: "color",
|
||||||
|
span: 24,
|
||||||
|
defaultValue: null,
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
layout: "colFormItem",
|
||||||
|
required: true,
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
document: "https://element-plus.org/zh-CN/component/color-picker",
|
||||||
|
},
|
||||||
|
"show-alpha": false,
|
||||||
|
"color-format": "",
|
||||||
|
disabled: false,
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "上传",
|
||||||
|
tag: "el-upload",
|
||||||
|
tagIcon: "upload",
|
||||||
|
layout: "colFormItem",
|
||||||
|
defaultValue: null,
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: null,
|
||||||
|
required: true,
|
||||||
|
span: 24,
|
||||||
|
showTip: false,
|
||||||
|
buttonText: "点击上传",
|
||||||
|
regList: [],
|
||||||
|
changeTag: true,
|
||||||
|
fileSize: 2,
|
||||||
|
sizeUnit: "MB",
|
||||||
|
document: "https://element-plus.org/zh-CN/component/upload",
|
||||||
|
},
|
||||||
|
__slot__: {
|
||||||
|
"list-type": true,
|
||||||
|
},
|
||||||
|
action: import.meta.env.VUE_APP_BASE_API + "/system/oss/upload",
|
||||||
|
disabled: false,
|
||||||
|
accept: "",
|
||||||
|
name: "file",
|
||||||
|
"auto-upload": true,
|
||||||
|
"list-type": "text",
|
||||||
|
multiple: false,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 布局型组件 【左面板】
|
||||||
|
export const layoutComponents = [
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
layout: "rowFormItem",
|
||||||
|
tagIcon: "row",
|
||||||
|
label: "行容器",
|
||||||
|
layoutTree: true,
|
||||||
|
document:
|
||||||
|
"https://element-plus.org/zh-CN/component/layout#row-attributes",
|
||||||
|
},
|
||||||
|
type: "default",
|
||||||
|
justify: "start",
|
||||||
|
align: "top",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "按钮",
|
||||||
|
showLabel: true,
|
||||||
|
changeTag: true,
|
||||||
|
labelWidth: null,
|
||||||
|
tag: "el-button",
|
||||||
|
tagIcon: "button",
|
||||||
|
span: 24,
|
||||||
|
layout: "colFormItem",
|
||||||
|
document: "https://element-plus.org/zh-CN/component/button",
|
||||||
|
},
|
||||||
|
__slot__: {
|
||||||
|
default: "主要按钮",
|
||||||
|
},
|
||||||
|
type: "primary",
|
||||||
|
icon: "el-icon-search",
|
||||||
|
round: false,
|
||||||
|
size: "default",
|
||||||
|
plain: false,
|
||||||
|
circle: false,
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
layout: "colFormItem",
|
||||||
|
tagIcon: "table",
|
||||||
|
tag: "el-table",
|
||||||
|
document: "https://element-plus.org/zh-CN/component/table",
|
||||||
|
span: 24,
|
||||||
|
formId: 101,
|
||||||
|
renderKey: 1595761764203,
|
||||||
|
componentName: "row101",
|
||||||
|
showLabel: true,
|
||||||
|
changeTag: true,
|
||||||
|
labelWidth: null,
|
||||||
|
label: "表格[开发中]",
|
||||||
|
dataType: "dynamic",
|
||||||
|
method: "get",
|
||||||
|
dataPath: "list",
|
||||||
|
dataConsumer: "data",
|
||||||
|
url: "https://www.fastmock.site/mock/f8d7a54fb1e60561e2f720d5a810009d/fg/tableData",
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
layout: "raw",
|
||||||
|
tag: "el-table-column",
|
||||||
|
renderKey: 15957617660153,
|
||||||
|
},
|
||||||
|
prop: "date",
|
||||||
|
label: "日期",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
layout: "raw",
|
||||||
|
tag: "el-table-column",
|
||||||
|
renderKey: 15957617660152,
|
||||||
|
},
|
||||||
|
prop: "address",
|
||||||
|
label: "地址",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
layout: "raw",
|
||||||
|
tag: "el-table-column",
|
||||||
|
renderKey: 15957617660151,
|
||||||
|
},
|
||||||
|
prop: "name",
|
||||||
|
label: "名称",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
layout: "raw",
|
||||||
|
tag: "el-table-column",
|
||||||
|
renderKey: 1595774496335,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: "按钮",
|
||||||
|
tag: "el-button",
|
||||||
|
tagIcon: "button",
|
||||||
|
layout: "raw",
|
||||||
|
renderKey: 1595779809901,
|
||||||
|
},
|
||||||
|
__slot__: {
|
||||||
|
default: "主要按钮",
|
||||||
|
},
|
||||||
|
type: "primary",
|
||||||
|
icon: "el-icon-search",
|
||||||
|
round: false,
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
label: "操作",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
data: [],
|
||||||
|
directives: [
|
||||||
|
{
|
||||||
|
name: "loading",
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
border: true,
|
||||||
|
type: "default",
|
||||||
|
justify: "start",
|
||||||
|
align: "top",
|
||||||
|
},
|
||||||
|
];
|
||||||
18
src/utils/generator/css.js
Normal file
18
src/utils/generator/css.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const styles = {
|
||||||
|
'el-rate': '.el-rate{display: inline-block; vertical-align: text-top;}',
|
||||||
|
'el-upload': '.el-upload__tip{line-height: 1.2;}'
|
||||||
|
}
|
||||||
|
|
||||||
|
function addCss(cssList, el) {
|
||||||
|
const css = styles[el.tag]
|
||||||
|
css && cssList.indexOf(css) === -1 && cssList.push(css)
|
||||||
|
if (el.children) {
|
||||||
|
el.children.forEach(el2 => addCss(cssList, el2))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function makeUpCss(conf) {
|
||||||
|
const cssList = []
|
||||||
|
conf.fields.forEach(el => addCss(cssList, el))
|
||||||
|
return cssList.join('\n')
|
||||||
|
}
|
||||||
37
src/utils/generator/drawingDefault.js
Normal file
37
src/utils/generator/drawingDefault.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
export default [
|
||||||
|
{
|
||||||
|
__config__: {
|
||||||
|
label: '单行文本',
|
||||||
|
labelWidth: null,
|
||||||
|
showLabel: true,
|
||||||
|
changeTag: true,
|
||||||
|
tag: 'el-input',
|
||||||
|
tagIcon: 'input',
|
||||||
|
defaultValue: undefined,
|
||||||
|
required: true,
|
||||||
|
layout: 'colFormItem',
|
||||||
|
span: 24,
|
||||||
|
document: 'https://element-plus.org/zh-CN/component/input',
|
||||||
|
// 正则校验规则
|
||||||
|
regList: [{
|
||||||
|
pattern: '/^1(3|4|5|7|8|9)\\d{9}$/',
|
||||||
|
message: '手机号格式错误'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
// 组件的插槽属性
|
||||||
|
__slot__: {
|
||||||
|
prepend: '',
|
||||||
|
append: ''
|
||||||
|
},
|
||||||
|
__vModel__: 'mobile',
|
||||||
|
placeholder: '请输入手机号',
|
||||||
|
style: { width: '100%' },
|
||||||
|
clearable: true,
|
||||||
|
'prefix-icon': 'el-icon-mobile',
|
||||||
|
'suffix-icon': '',
|
||||||
|
maxlength: 11,
|
||||||
|
'show-word-limit': true,
|
||||||
|
readonly: false,
|
||||||
|
disabled: false
|
||||||
|
}
|
||||||
|
]
|
||||||
399
src/utils/generator/html.js
Normal file
399
src/utils/generator/html.js
Normal file
@ -0,0 +1,399 @@
|
|||||||
|
/* eslint-disable max-len */
|
||||||
|
import ruleTrigger from './ruleTrigger'
|
||||||
|
|
||||||
|
let confGlobal
|
||||||
|
let someSpanIsNot24
|
||||||
|
|
||||||
|
export function dialogWrapper(str) {
|
||||||
|
return `<el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" title="Dialog Title">
|
||||||
|
${str}
|
||||||
|
<div slot="footer">
|
||||||
|
<el-button @click="close">取消</el-button>
|
||||||
|
<el-button type="primary" @click="handleConfirm">确定</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function vueTemplate(str) {
|
||||||
|
return `<template>
|
||||||
|
<div>
|
||||||
|
${str}
|
||||||
|
</div>
|
||||||
|
</template>`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function vueScript(str) {
|
||||||
|
return `<script>
|
||||||
|
${str}
|
||||||
|
</script>`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function cssStyle(cssStr) {
|
||||||
|
return `<style>
|
||||||
|
${cssStr}
|
||||||
|
</style>`
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildFormTemplate(scheme, child, type) {
|
||||||
|
let labelPosition = ''
|
||||||
|
if (scheme.labelPosition !== 'right') {
|
||||||
|
labelPosition = `label-position="${scheme.labelPosition}"`
|
||||||
|
}
|
||||||
|
const disabled = scheme.disabled ? `:disabled="${scheme.disabled}"` : ''
|
||||||
|
let str = `<el-form ref="${scheme.formRef}" :model="${scheme.formModel}" :rules="${scheme.formRules}" size="${scheme.size}" ${disabled} label-width="${scheme.labelWidth}px" ${labelPosition}>
|
||||||
|
${child}
|
||||||
|
${buildFromBtns(scheme, type)}
|
||||||
|
</el-form>`
|
||||||
|
if (someSpanIsNot24) {
|
||||||
|
str = `<el-row :gutter="${scheme.gutter}">
|
||||||
|
${str}
|
||||||
|
</el-row>`
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildFromBtns(scheme, type) {
|
||||||
|
let str = ''
|
||||||
|
if (scheme.formBtns && type === 'file') {
|
||||||
|
str = `<el-form-item size="large">
|
||||||
|
<el-button type="primary" @click="submitForm">提交</el-button>
|
||||||
|
<el-button @click="resetForm">重置</el-button>
|
||||||
|
</el-form-item>`
|
||||||
|
if (someSpanIsNot24) {
|
||||||
|
str = `<el-col :span="24">
|
||||||
|
${str}
|
||||||
|
</el-col>`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
// span不为24的用el-col包裹
|
||||||
|
function colWrapper(scheme, str) {
|
||||||
|
if (someSpanIsNot24 || scheme.__config__.span !== 24) {
|
||||||
|
return `<el-col :span="${scheme.__config__.span}">
|
||||||
|
${str}
|
||||||
|
</el-col>`
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
const layouts = {
|
||||||
|
colFormItem(scheme) {
|
||||||
|
const config = scheme.__config__
|
||||||
|
let labelWidth = ''
|
||||||
|
let label = `label="${config.label}"`
|
||||||
|
if (config.labelWidth && config.labelWidth !== confGlobal.labelWidth) {
|
||||||
|
labelWidth = `label-width="${config.labelWidth}px"`
|
||||||
|
}
|
||||||
|
if (config.showLabel === false) {
|
||||||
|
labelWidth = 'label-width="0"'
|
||||||
|
label = ''
|
||||||
|
}
|
||||||
|
const required = !ruleTrigger[config.tag] && config.required ? 'required' : ''
|
||||||
|
const tagDom = tags[config.tag] ? tags[config.tag](scheme) : null
|
||||||
|
let str = `<el-form-item ${labelWidth} ${label} prop="${scheme.__vModel__}" ${required}>
|
||||||
|
${tagDom}
|
||||||
|
</el-form-item>`
|
||||||
|
str = colWrapper(scheme, str)
|
||||||
|
return str
|
||||||
|
},
|
||||||
|
rowFormItem(scheme) {
|
||||||
|
const config = scheme.__config__
|
||||||
|
const type = scheme.type === 'default' ? '' : `type="${scheme.type}"`
|
||||||
|
const justify = scheme.type === 'default' ? '' : `justify="${scheme.justify}"`
|
||||||
|
const align = scheme.type === 'default' ? '' : `align="${scheme.align}"`
|
||||||
|
const gutter = scheme.gutter ? `:gutter="${scheme.gutter}"` : ''
|
||||||
|
const children = config.children.map(el => layouts[el.__config__.layout](el))
|
||||||
|
let str = `<el-row ${type} ${justify} ${align} ${gutter}>
|
||||||
|
${children.join('\n')}
|
||||||
|
</el-row>`
|
||||||
|
str = colWrapper(scheme, str)
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tags = {
|
||||||
|
'el-button': el => {
|
||||||
|
const {
|
||||||
|
tag, disabled
|
||||||
|
} = attrBuilder(el)
|
||||||
|
const type = el.type ? `type="${el.type}"` : ''
|
||||||
|
const icon = el.icon ? `icon="${el.icon}"` : ''
|
||||||
|
const round = el.round ? 'round' : ''
|
||||||
|
const size = el.size ? `size="${el.size}"` : ''
|
||||||
|
const plain = el.plain ? 'plain' : ''
|
||||||
|
const circle = el.circle ? 'circle' : ''
|
||||||
|
let child = buildElButtonChild(el)
|
||||||
|
|
||||||
|
if (child) child = `\n${child}\n` // 换行
|
||||||
|
return `<${tag} ${type} ${icon} ${round} ${size} ${plain} ${disabled} ${circle}>${child}</${tag}>`
|
||||||
|
},
|
||||||
|
'el-input': el => {
|
||||||
|
const {
|
||||||
|
tag, disabled, vModel, clearable, placeholder, width
|
||||||
|
} = attrBuilder(el)
|
||||||
|
const maxlength = el.maxlength ? `:maxlength="${el.maxlength}"` : ''
|
||||||
|
const showWordLimit = el['show-word-limit'] ? 'show-word-limit' : ''
|
||||||
|
const readonly = el.readonly ? 'readonly' : ''
|
||||||
|
const prefixIcon = el['prefix-icon'] ? `prefix-icon='${el['prefix-icon']}'` : ''
|
||||||
|
const suffixIcon = el['suffix-icon'] ? `suffix-icon='${el['suffix-icon']}'` : ''
|
||||||
|
const showPassword = el['show-password'] ? 'show-password' : ''
|
||||||
|
const type = el.type ? `type="${el.type}"` : ''
|
||||||
|
const autosize = el.autosize && el.autosize.minRows
|
||||||
|
? `:autosize="{minRows: ${el.autosize.minRows}, maxRows: ${el.autosize.maxRows}}"`
|
||||||
|
: ''
|
||||||
|
let child = buildElInputChild(el)
|
||||||
|
|
||||||
|
if (child) child = `\n${child}\n` // 换行
|
||||||
|
return `<${tag} ${vModel} ${type} ${placeholder} ${maxlength} ${showWordLimit} ${readonly} ${disabled} ${clearable} ${prefixIcon} ${suffixIcon} ${showPassword} ${autosize} ${width}>${child}</${tag}>`
|
||||||
|
},
|
||||||
|
'el-input-number': el => {
|
||||||
|
const {
|
||||||
|
tag, disabled, vModel, placeholder
|
||||||
|
} = attrBuilder(el)
|
||||||
|
const controlsPosition = el['controls-position'] ? `controls-position=${el['controls-position']}` : ''
|
||||||
|
const min = el.min ? `:min='${el.min}'` : ''
|
||||||
|
const max = el.max ? `:max='${el.max}'` : ''
|
||||||
|
const step = el.step ? `:step='${el.step}'` : ''
|
||||||
|
const stepStrictly = el['step-strictly'] ? 'step-strictly' : ''
|
||||||
|
const precision = el.precision ? `:precision='${el.precision}'` : ''
|
||||||
|
|
||||||
|
return `<${tag} ${vModel} ${placeholder} ${step} ${stepStrictly} ${precision} ${controlsPosition} ${min} ${max} ${disabled}></${tag}>`
|
||||||
|
},
|
||||||
|
'el-select': el => {
|
||||||
|
const {
|
||||||
|
tag, disabled, vModel, clearable, placeholder, width
|
||||||
|
} = attrBuilder(el)
|
||||||
|
const filterable = el.filterable ? 'filterable' : ''
|
||||||
|
const multiple = el.multiple ? 'multiple' : ''
|
||||||
|
let child = buildElSelectChild(el)
|
||||||
|
|
||||||
|
if (child) child = `\n${child}\n` // 换行
|
||||||
|
return `<${tag} ${vModel} ${placeholder} ${disabled} ${multiple} ${filterable} ${clearable} ${width}>${child}</${tag}>`
|
||||||
|
},
|
||||||
|
'el-radio-group': el => {
|
||||||
|
const { tag, disabled, vModel } = attrBuilder(el)
|
||||||
|
const size = `size="${el.size}"`
|
||||||
|
let child = buildElRadioGroupChild(el)
|
||||||
|
|
||||||
|
if (child) child = `\n${child}\n` // 换行
|
||||||
|
return `<${tag} ${vModel} ${size} ${disabled}>${child}</${tag}>`
|
||||||
|
},
|
||||||
|
'el-checkbox-group': el => {
|
||||||
|
const { tag, disabled, vModel } = attrBuilder(el)
|
||||||
|
const size = `size="${el.size}"`
|
||||||
|
const min = el.min ? `:min="${el.min}"` : ''
|
||||||
|
const max = el.max ? `:max="${el.max}"` : ''
|
||||||
|
let child = buildElCheckboxGroupChild(el)
|
||||||
|
|
||||||
|
if (child) child = `\n${child}\n` // 换行
|
||||||
|
return `<${tag} ${vModel} ${min} ${max} ${size} ${disabled}>${child}</${tag}>`
|
||||||
|
},
|
||||||
|
'el-switch': el => {
|
||||||
|
const { tag, disabled, vModel } = attrBuilder(el)
|
||||||
|
const activeText = el['active-text'] ? `active-text="${el['active-text']}"` : ''
|
||||||
|
const inactiveText = el['inactive-text'] ? `inactive-text="${el['inactive-text']}"` : ''
|
||||||
|
const activeColor = el['active-color'] ? `active-color="${el['active-color']}"` : ''
|
||||||
|
const inactiveColor = el['inactive-color'] ? `inactive-color="${el['inactive-color']}"` : ''
|
||||||
|
const activeValue = el['active-value'] !== true ? `:active-value='${JSON.stringify(el['active-value'])}'` : ''
|
||||||
|
const inactiveValue = el['inactive-value'] !== false ? `:inactive-value='${JSON.stringify(el['inactive-value'])}'` : ''
|
||||||
|
|
||||||
|
return `<${tag} ${vModel} ${activeText} ${inactiveText} ${activeColor} ${inactiveColor} ${activeValue} ${inactiveValue} ${disabled}></${tag}>`
|
||||||
|
},
|
||||||
|
'el-cascader': el => {
|
||||||
|
const {
|
||||||
|
tag, disabled, vModel, clearable, placeholder, width
|
||||||
|
} = attrBuilder(el)
|
||||||
|
const options = el.options ? `:options="${el.__vModel__}Options"` : ''
|
||||||
|
const props = el.props ? `:props="${el.__vModel__}Props"` : ''
|
||||||
|
const showAllLevels = el['show-all-levels'] ? '' : ':show-all-levels="false"'
|
||||||
|
const filterable = el.filterable ? 'filterable' : ''
|
||||||
|
const separator = el.separator === '/' ? '' : `separator="${el.separator}"`
|
||||||
|
|
||||||
|
return `<${tag} ${vModel} ${options} ${props} ${width} ${showAllLevels} ${placeholder} ${separator} ${filterable} ${clearable} ${disabled}></${tag}>`
|
||||||
|
},
|
||||||
|
'el-slider': el => {
|
||||||
|
const { tag, disabled, vModel } = attrBuilder(el)
|
||||||
|
const min = el.min ? `:min='${el.min}'` : ''
|
||||||
|
const max = el.max ? `:max='${el.max}'` : ''
|
||||||
|
const step = el.step ? `:step='${el.step}'` : ''
|
||||||
|
const range = el.range ? 'range' : ''
|
||||||
|
const showStops = el['show-stops'] ? `:show-stops="${el['show-stops']}"` : ''
|
||||||
|
|
||||||
|
return `<${tag} ${min} ${max} ${step} ${vModel} ${range} ${showStops} ${disabled}></${tag}>`
|
||||||
|
},
|
||||||
|
'el-time-picker': el => {
|
||||||
|
const {
|
||||||
|
tag, disabled, vModel, clearable, placeholder, width
|
||||||
|
} = attrBuilder(el)
|
||||||
|
const startPlaceholder = el['start-placeholder'] ? `start-placeholder="${el['start-placeholder']}"` : ''
|
||||||
|
const endPlaceholder = el['end-placeholder'] ? `end-placeholder="${el['end-placeholder']}"` : ''
|
||||||
|
const rangeSeparator = el['range-separator'] ? `range-separator="${el['range-separator']}"` : ''
|
||||||
|
const isRange = el['is-range'] ? 'is-range' : ''
|
||||||
|
const format = el.format ? `format="${el.format}"` : ''
|
||||||
|
const valueFormat = el['value-format'] ? `value-format="${el['value-format']}"` : ''
|
||||||
|
const pickerOptions = el['picker-options'] ? `:picker-options='${JSON.stringify(el['picker-options'])}'` : ''
|
||||||
|
|
||||||
|
return `<${tag} ${vModel} ${isRange} ${format} ${valueFormat} ${pickerOptions} ${width} ${placeholder} ${startPlaceholder} ${endPlaceholder} ${rangeSeparator} ${clearable} ${disabled}></${tag}>`
|
||||||
|
},
|
||||||
|
'el-date-picker': el => {
|
||||||
|
const {
|
||||||
|
tag, disabled, vModel, clearable, placeholder, width
|
||||||
|
} = attrBuilder(el)
|
||||||
|
const startPlaceholder = el['start-placeholder'] ? `start-placeholder="${el['start-placeholder']}"` : ''
|
||||||
|
const endPlaceholder = el['end-placeholder'] ? `end-placeholder="${el['end-placeholder']}"` : ''
|
||||||
|
const rangeSeparator = el['range-separator'] ? `range-separator="${el['range-separator']}"` : ''
|
||||||
|
const format = el.format ? `format="${el.format}"` : ''
|
||||||
|
const valueFormat = el['value-format'] ? `value-format="${el['value-format']}"` : ''
|
||||||
|
const type = el.type === 'date' ? '' : `type="${el.type}"`
|
||||||
|
const readonly = el.readonly ? 'readonly' : ''
|
||||||
|
|
||||||
|
return `<${tag} ${type} ${vModel} ${format} ${valueFormat} ${width} ${placeholder} ${startPlaceholder} ${endPlaceholder} ${rangeSeparator} ${clearable} ${readonly} ${disabled}></${tag}>`
|
||||||
|
},
|
||||||
|
'el-rate': el => {
|
||||||
|
const { tag, disabled, vModel } = attrBuilder(el)
|
||||||
|
const max = el.max ? `:max='${el.max}'` : ''
|
||||||
|
const allowHalf = el['allow-half'] ? 'allow-half' : ''
|
||||||
|
const showText = el['show-text'] ? 'show-text' : ''
|
||||||
|
const showScore = el['show-score'] ? 'show-score' : ''
|
||||||
|
|
||||||
|
return `<${tag} ${vModel} ${max} ${allowHalf} ${showText} ${showScore} ${disabled}></${tag}>`
|
||||||
|
},
|
||||||
|
'el-color-picker': el => {
|
||||||
|
const { tag, disabled, vModel } = attrBuilder(el)
|
||||||
|
const size = `size="${el.size}"`
|
||||||
|
const showAlpha = el['show-alpha'] ? 'show-alpha' : ''
|
||||||
|
const colorFormat = el['color-format'] ? `color-format="${el['color-format']}"` : ''
|
||||||
|
|
||||||
|
return `<${tag} ${vModel} ${size} ${showAlpha} ${colorFormat} ${disabled}></${tag}>`
|
||||||
|
},
|
||||||
|
'el-upload': el => {
|
||||||
|
const { tag } = el.__config__
|
||||||
|
const disabled = el.disabled ? ':disabled=\'true\'' : ''
|
||||||
|
const action = el.action ? `:action="${el.__vModel__}Action"` : ''
|
||||||
|
const multiple = el.multiple ? 'multiple' : ''
|
||||||
|
const listType = el['list-type'] !== 'text' ? `list-type="${el['list-type']}"` : ''
|
||||||
|
const accept = el.accept ? `accept="${el.accept}"` : ''
|
||||||
|
const name = el.name !== 'file' ? `name="${el.name}"` : ''
|
||||||
|
const autoUpload = el['auto-upload'] === false ? ':auto-upload="false"' : ''
|
||||||
|
const beforeUpload = `:before-upload="${el.__vModel__}BeforeUpload"`
|
||||||
|
const fileList = `:file-list="${el.__vModel__}fileList"`
|
||||||
|
const ref = `ref="${el.__vModel__}"`
|
||||||
|
let child = buildElUploadChild(el)
|
||||||
|
|
||||||
|
if (child) child = `\n${child}\n` // 换行
|
||||||
|
return `<${tag} ${ref} ${fileList} ${action} ${autoUpload} ${multiple} ${beforeUpload} ${listType} ${accept} ${name} ${disabled}>${child}</${tag}>`
|
||||||
|
},
|
||||||
|
tinymce: el => {
|
||||||
|
const { tag, vModel, placeholder } = attrBuilder(el)
|
||||||
|
const height = el.height ? `:height="${el.height}"` : ''
|
||||||
|
const branding = el.branding ? `:branding="${el.branding}"` : ''
|
||||||
|
return `<${tag} ${vModel} ${placeholder} ${height} ${branding}></${tag}>`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function attrBuilder(el) {
|
||||||
|
return {
|
||||||
|
tag: el.__config__.tag,
|
||||||
|
vModel: `v-model="${confGlobal.formModel}.${el.__vModel__}"`,
|
||||||
|
clearable: el.clearable ? 'clearable' : '',
|
||||||
|
placeholder: el.placeholder ? `placeholder="${el.placeholder}"` : '',
|
||||||
|
width: el.style && el.style.width ? ':style="{width: \'100%\'}"' : '',
|
||||||
|
disabled: el.disabled ? ':disabled=\'true\'' : ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// el-buttin 子级
|
||||||
|
function buildElButtonChild(scheme) {
|
||||||
|
const children = []
|
||||||
|
const slot = scheme.__slot__ || {}
|
||||||
|
if (slot.default) {
|
||||||
|
children.push(slot.default)
|
||||||
|
}
|
||||||
|
return children.join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
// el-input 子级
|
||||||
|
function buildElInputChild(scheme) {
|
||||||
|
const children = []
|
||||||
|
const slot = scheme.__slot__
|
||||||
|
if (slot && slot.prepend) {
|
||||||
|
children.push(`<template slot="prepend">${slot.prepend}</template>`)
|
||||||
|
}
|
||||||
|
if (slot && slot.append) {
|
||||||
|
children.push(`<template slot="append">${slot.append}</template>`)
|
||||||
|
}
|
||||||
|
return children.join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
// el-select 子级
|
||||||
|
function buildElSelectChild(scheme) {
|
||||||
|
const children = []
|
||||||
|
const slot = scheme.__slot__
|
||||||
|
if (slot && slot.options && slot.options.length) {
|
||||||
|
children.push(`<el-option v-for="(item, index) in ${scheme.__vModel__}Options" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>`)
|
||||||
|
}
|
||||||
|
return children.join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
// el-radio-group 子级
|
||||||
|
function buildElRadioGroupChild(scheme) {
|
||||||
|
const children = []
|
||||||
|
const slot = scheme.__slot__
|
||||||
|
const config = scheme.__config__
|
||||||
|
if (slot && slot.options && slot.options.length) {
|
||||||
|
const tag = config.optionType === 'button' ? 'el-radio-button' : 'el-radio'
|
||||||
|
const border = config.border ? 'border' : ''
|
||||||
|
children.push(`<${tag} v-for="(item, index) in ${scheme.__vModel__}Options" :key="index" :label="item.value" :disabled="item.disabled" ${border}>{{item.label}}</${tag}>`)
|
||||||
|
}
|
||||||
|
return children.join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
// el-checkbox-group 子级
|
||||||
|
function buildElCheckboxGroupChild(scheme) {
|
||||||
|
const children = []
|
||||||
|
const slot = scheme.__slot__
|
||||||
|
const config = scheme.__config__
|
||||||
|
if (slot && slot.options && slot.options.length) {
|
||||||
|
const tag = config.optionType === 'button' ? 'el-checkbox-button' : 'el-checkbox'
|
||||||
|
const border = config.border ? 'border' : ''
|
||||||
|
children.push(`<${tag} v-for="(item, index) in ${scheme.__vModel__}Options" :key="index" :label="item.value" :disabled="item.disabled" ${border}>{{item.label}}</${tag}>`)
|
||||||
|
}
|
||||||
|
return children.join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
// el-upload 子级
|
||||||
|
function buildElUploadChild(scheme) {
|
||||||
|
const list = []
|
||||||
|
const config = scheme.__config__
|
||||||
|
if (scheme['list-type'] === 'picture-card') list.push('<i class="el-icon-plus"></i>')
|
||||||
|
else list.push(`<el-button size="small" type="primary" icon="el-icon-upload">${config.buttonText}</el-button>`)
|
||||||
|
if (config.showTip) list.push(`<div slot="tip" class="el-upload__tip">只能上传不超过 ${config.fileSize}${config.sizeUnit} 的${scheme.accept}文件</div>`)
|
||||||
|
return list.join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组装html代码。【入口函数】
|
||||||
|
* @param {Object} formConfig 整个表单配置
|
||||||
|
* @param {String} type 生成类型,文件或弹窗等
|
||||||
|
*/
|
||||||
|
export function makeUpHtml(formConfig, type) {
|
||||||
|
const htmlList = []
|
||||||
|
confGlobal = formConfig
|
||||||
|
// 判断布局是否都沾满了24个栅格,以备后续简化代码结构
|
||||||
|
someSpanIsNot24 = formConfig.fields.some(item => item.__config__.span !== 24)
|
||||||
|
// 遍历渲染每个组件成html
|
||||||
|
formConfig.fields.forEach(el => {
|
||||||
|
htmlList.push(layouts[el.__config__.layout](el))
|
||||||
|
})
|
||||||
|
const htmlStr = htmlList.join('\n')
|
||||||
|
// 将组件代码放进form标签
|
||||||
|
let temp = buildFormTemplate(formConfig, htmlStr, type)
|
||||||
|
// dialog标签包裹代码
|
||||||
|
if (type === 'dialog') {
|
||||||
|
temp = dialogWrapper(temp)
|
||||||
|
}
|
||||||
|
confGlobal = null
|
||||||
|
return temp
|
||||||
|
}
|
||||||
1
src/utils/generator/icon.json
Normal file
1
src/utils/generator/icon.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
["platform-eleme","eleme","delete-solid","delete","s-tools","setting","user-solid","user","phone","phone-outline","more","more-outline","star-on","star-off","s-goods","goods","warning","warning-outline","question","info","remove","circle-plus","success","error","zoom-in","zoom-out","remove-outline","circle-plus-outline","circle-check","circle-close","s-help","help","minus","plus","check","close","picture","picture-outline","picture-outline-round","upload","upload2","download","camera-solid","camera","video-camera-solid","video-camera","message-solid","bell","s-cooperation","s-order","s-platform","s-fold","s-unfold","s-operation","s-promotion","s-home","s-release","s-ticket","s-management","s-open","s-shop","s-marketing","s-flag","s-comment","s-finance","s-claim","s-custom","s-opportunity","s-data","s-check","s-grid","menu","share","d-caret","caret-left","caret-right","caret-bottom","caret-top","bottom-left","bottom-right","back","right","bottom","top","top-left","top-right","arrow-left","arrow-right","arrow-down","arrow-up","d-arrow-left","d-arrow-right","video-pause","video-play","refresh","refresh-right","refresh-left","finished","sort","sort-up","sort-down","rank","loading","view","c-scale-to-original","date","edit","edit-outline","folder","folder-opened","folder-add","folder-remove","folder-delete","folder-checked","tickets","document-remove","document-delete","document-copy","document-checked","document","document-add","printer","paperclip","takeaway-box","search","monitor","attract","mobile","scissors","umbrella","headset","brush","mouse","coordinate","magic-stick","reading","data-line","data-board","pie-chart","data-analysis","collection-tag","film","suitcase","suitcase-1","receiving","collection","files","notebook-1","notebook-2","toilet-paper","office-building","school","table-lamp","house","no-smoking","smoking","shopping-cart-full","shopping-cart-1","shopping-cart-2","shopping-bag-1","shopping-bag-2","sold-out","sell","present","box","bank-card","money","coin","wallet","discount","price-tag","news","guide","male","female","thumb","cpu","link","connection","open","turn-off","set-up","chat-round","chat-line-round","chat-square","chat-dot-round","chat-dot-square","chat-line-square","message","postcard","position","turn-off-microphone","microphone","close-notification","bangzhu","time","odometer","crop","aim","switch-button","full-screen","copy-document","mic","stopwatch","medal-1","medal","trophy","trophy-1","first-aid-kit","discover","place","location","location-outline","location-information","add-location","delete-location","map-location","alarm-clock","timer","watch-1","watch","lock","unlock","key","service","mobile-phone","bicycle","truck","ship","basketball","football","soccer","baseball","wind-power","light-rain","lightning","heavy-rain","sunrise","sunrise-1","sunset","sunny","cloudy","partly-cloudy","cloudy-and-sunny","moon","moon-night","dish","dish-1","food","chicken","fork-spoon","knife-fork","burger","tableware","sugar","dessert","ice-cream","hot-water","water-cup","coffee-cup","cold-drink","goblet","goblet-full","goblet-square","goblet-square-full","refrigerator","grape","watermelon","cherry","apple","pear","orange","coffee","ice-tea","ice-drink","milk-tea","potato-strips","lollipop","ice-cream-square","ice-cream-round"]
|
||||||
271
src/utils/generator/js.js
Normal file
271
src/utils/generator/js.js
Normal file
@ -0,0 +1,271 @@
|
|||||||
|
import { isArray } from 'util'
|
||||||
|
import { exportDefault, titleCase, deepClone } from '@/utils/index'
|
||||||
|
import ruleTrigger from './ruleTrigger'
|
||||||
|
|
||||||
|
const units = {
|
||||||
|
KB: '1024',
|
||||||
|
MB: '1024 / 1024',
|
||||||
|
GB: '1024 / 1024 / 1024'
|
||||||
|
}
|
||||||
|
let confGlobal
|
||||||
|
const inheritAttrs = {
|
||||||
|
file: '',
|
||||||
|
dialog: 'inheritAttrs: false,'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组装js 【入口函数】
|
||||||
|
* @param {Object} formConfig 整个表单配置
|
||||||
|
* @param {String} type 生成类型,文件或弹窗等
|
||||||
|
*/
|
||||||
|
export function makeUpJs(formConfig, type) {
|
||||||
|
confGlobal = formConfig = deepClone(formConfig)
|
||||||
|
const dataList = []
|
||||||
|
const ruleList = []
|
||||||
|
const optionsList = []
|
||||||
|
const propsList = []
|
||||||
|
const methodList = mixinMethod(type)
|
||||||
|
const uploadVarList = []
|
||||||
|
const created = []
|
||||||
|
|
||||||
|
formConfig.fields.forEach(el => {
|
||||||
|
buildAttributes(el, dataList, ruleList, optionsList, methodList, propsList, uploadVarList, created)
|
||||||
|
})
|
||||||
|
|
||||||
|
const script = buildexport(
|
||||||
|
formConfig,
|
||||||
|
type,
|
||||||
|
dataList.join('\n'),
|
||||||
|
ruleList.join('\n'),
|
||||||
|
optionsList.join('\n'),
|
||||||
|
uploadVarList.join('\n'),
|
||||||
|
propsList.join('\n'),
|
||||||
|
methodList.join('\n'),
|
||||||
|
created.join('\n')
|
||||||
|
)
|
||||||
|
confGlobal = null
|
||||||
|
return script
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建组件属性
|
||||||
|
function buildAttributes(scheme, dataList, ruleList, optionsList, methodList, propsList, uploadVarList, created) {
|
||||||
|
const config = scheme.__config__
|
||||||
|
const slot = scheme.__slot__
|
||||||
|
buildData(scheme, dataList)
|
||||||
|
buildRules(scheme, ruleList)
|
||||||
|
|
||||||
|
// 特殊处理options属性
|
||||||
|
if (scheme.options || (slot && slot.options && slot.options.length)) {
|
||||||
|
buildOptions(scheme, optionsList)
|
||||||
|
if (config.dataType === 'dynamic') {
|
||||||
|
const model = `${scheme.__vModel__}Options`
|
||||||
|
const options = titleCase(model)
|
||||||
|
const methodName = `get${options}`
|
||||||
|
buildOptionMethod(methodName, model, methodList, scheme)
|
||||||
|
callInCreated(methodName, created)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理props
|
||||||
|
if (scheme.props && scheme.props.props) {
|
||||||
|
buildProps(scheme, propsList)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理el-upload的action
|
||||||
|
if (scheme.action && config.tag === 'el-upload') {
|
||||||
|
uploadVarList.push(
|
||||||
|
`${scheme.__vModel__}Action: '${scheme.action}',
|
||||||
|
${scheme.__vModel__}fileList: [],`
|
||||||
|
)
|
||||||
|
methodList.push(buildBeforeUpload(scheme))
|
||||||
|
// 非自动上传时,生成手动上传的函数
|
||||||
|
if (!scheme['auto-upload']) {
|
||||||
|
methodList.push(buildSubmitUpload(scheme))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建子级组件属性
|
||||||
|
if (config.children) {
|
||||||
|
config.children.forEach(item => {
|
||||||
|
buildAttributes(item, dataList, ruleList, optionsList, methodList, propsList, uploadVarList, created)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在Created调用函数
|
||||||
|
function callInCreated(methodName, created) {
|
||||||
|
created.push(`this.${methodName}()`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 混入处理函数
|
||||||
|
function mixinMethod(type) {
|
||||||
|
const list = []; const
|
||||||
|
minxins = {
|
||||||
|
file: confGlobal.formBtns ? {
|
||||||
|
submitForm: `submitForm() {
|
||||||
|
this.$refs['${confGlobal.formRef}'].validate(valid => {
|
||||||
|
if(!valid) return
|
||||||
|
// TODO 提交表单
|
||||||
|
})
|
||||||
|
},`,
|
||||||
|
resetForm: `resetForm() {
|
||||||
|
this.$refs['${confGlobal.formRef}'].resetFields()
|
||||||
|
},`
|
||||||
|
} : null,
|
||||||
|
dialog: {
|
||||||
|
onOpen: 'onOpen() {},',
|
||||||
|
onClose: `onClose() {
|
||||||
|
this.$refs['${confGlobal.formRef}'].resetFields()
|
||||||
|
},`,
|
||||||
|
close: `close() {
|
||||||
|
this.$emit('update:visible', false)
|
||||||
|
},`,
|
||||||
|
handelConfirm: `handelConfirm() {
|
||||||
|
this.$refs['${confGlobal.formRef}'].validate(valid => {
|
||||||
|
if(!valid) return
|
||||||
|
this.close()
|
||||||
|
})
|
||||||
|
},`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const methods = minxins[type]
|
||||||
|
if (methods) {
|
||||||
|
Object.keys(methods).forEach(key => {
|
||||||
|
list.push(methods[key])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建data
|
||||||
|
function buildData(scheme, dataList) {
|
||||||
|
const config = scheme.__config__
|
||||||
|
if (scheme.__vModel__ === undefined) return
|
||||||
|
const defaultValue = JSON.stringify(config.defaultValue)
|
||||||
|
dataList.push(`${scheme.__vModel__}: ${defaultValue},`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建校验规则
|
||||||
|
function buildRules(scheme, ruleList) {
|
||||||
|
const config = scheme.__config__
|
||||||
|
if (scheme.__vModel__ === undefined) return
|
||||||
|
const rules = []
|
||||||
|
if (ruleTrigger[config.tag]) {
|
||||||
|
if (config.required) {
|
||||||
|
const type = isArray(config.defaultValue) ? 'type: \'array\',' : ''
|
||||||
|
let message = isArray(config.defaultValue) ? `请至少选择一个${config.label}` : scheme.placeholder
|
||||||
|
if (message === undefined) message = `${config.label}不能为空`
|
||||||
|
rules.push(`{ required: true, ${type} message: '${message}', trigger: '${ruleTrigger[config.tag]}' }`)
|
||||||
|
}
|
||||||
|
if (config.regList && isArray(config.regList)) {
|
||||||
|
config.regList.forEach(item => {
|
||||||
|
if (item.pattern) {
|
||||||
|
rules.push(
|
||||||
|
`{ pattern: ${eval(item.pattern)}, message: '${item.message}', trigger: '${ruleTrigger[config.tag]}' }`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
ruleList.push(`${scheme.__vModel__}: [${rules.join(',')}],`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建options
|
||||||
|
function buildOptions(scheme, optionsList) {
|
||||||
|
if (scheme.__vModel__ === undefined) return
|
||||||
|
// el-cascader直接有options属性,其他组件都是定义在slot中,所以有两处判断
|
||||||
|
let { options } = scheme
|
||||||
|
if (!options) options = scheme.__slot__.options
|
||||||
|
if (scheme.__config__.dataType === 'dynamic') { options = [] }
|
||||||
|
const str = `${scheme.__vModel__}Options: ${JSON.stringify(options)},`
|
||||||
|
optionsList.push(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildProps(scheme, propsList) {
|
||||||
|
const str = `${scheme.__vModel__}Props: ${JSON.stringify(scheme.props.props)},`
|
||||||
|
propsList.push(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
// el-upload的BeforeUpload
|
||||||
|
function buildBeforeUpload(scheme) {
|
||||||
|
const config = scheme.__config__
|
||||||
|
const unitNum = units[config.sizeUnit]; let rightSizeCode = ''; let acceptCode = ''; const
|
||||||
|
returnList = []
|
||||||
|
if (config.fileSize) {
|
||||||
|
rightSizeCode = `let isRightSize = file.size / ${unitNum} < ${config.fileSize}
|
||||||
|
if(!isRightSize){
|
||||||
|
this.$message.error('文件大小超过 ${config.fileSize}${config.sizeUnit}')
|
||||||
|
}`
|
||||||
|
returnList.push('isRightSize')
|
||||||
|
}
|
||||||
|
if (scheme.accept) {
|
||||||
|
acceptCode = `let isAccept = new RegExp('${scheme.accept}').test(file.type)
|
||||||
|
if(!isAccept){
|
||||||
|
this.$message.error('应该选择${scheme.accept}类型的文件')
|
||||||
|
}`
|
||||||
|
returnList.push('isAccept')
|
||||||
|
}
|
||||||
|
const str = `${scheme.__vModel__}BeforeUpload(file) {
|
||||||
|
${rightSizeCode}
|
||||||
|
${acceptCode}
|
||||||
|
return ${returnList.join('&&')}
|
||||||
|
},`
|
||||||
|
return returnList.length ? str : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
// el-upload的submit
|
||||||
|
function buildSubmitUpload(scheme) {
|
||||||
|
const str = `submitUpload() {
|
||||||
|
this.$refs['${scheme.__vModel__}'].submit()
|
||||||
|
},`
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildOptionMethod(methodName, model, methodList, scheme) {
|
||||||
|
const config = scheme.__config__
|
||||||
|
const str = `${methodName}() {
|
||||||
|
// 注意:this.$axios是通过Vue.prototype.$axios = axios挂载产生的
|
||||||
|
this.$axios({
|
||||||
|
method: '${config.method}',
|
||||||
|
url: '${config.url}'
|
||||||
|
}).then(resp => {
|
||||||
|
var { data } = resp
|
||||||
|
this.${model} = data.${config.dataKey}
|
||||||
|
})
|
||||||
|
},`
|
||||||
|
methodList.push(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
// js整体拼接
|
||||||
|
function buildexport(conf, type, data, rules, selectOptions, uploadVar, props, methods, created) {
|
||||||
|
const str = `${exportDefault}{
|
||||||
|
${inheritAttrs[type]}
|
||||||
|
components: {},
|
||||||
|
props: [],
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
${conf.formModel}: {
|
||||||
|
${data}
|
||||||
|
},
|
||||||
|
${conf.formRules}: {
|
||||||
|
${rules}
|
||||||
|
},
|
||||||
|
${uploadVar}
|
||||||
|
${selectOptions}
|
||||||
|
${props}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {},
|
||||||
|
watch: {},
|
||||||
|
created () {
|
||||||
|
${created}
|
||||||
|
},
|
||||||
|
mounted () {},
|
||||||
|
methods: {
|
||||||
|
${methods}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
return str
|
||||||
|
}
|
||||||
243
src/utils/generator/parser.js
Normal file
243
src/utils/generator/parser.js
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
import { deepClone } from '@/utils/index';
|
||||||
|
import { getToken } from '@/utils/auth';
|
||||||
|
import render from '@/utils/generator/render';
|
||||||
|
import axios from 'axios'
|
||||||
|
import Vue from 'vue';
|
||||||
|
|
||||||
|
Vue.prototype.$axios = axios
|
||||||
|
|
||||||
|
const ruleTrigger = {
|
||||||
|
'el-input': 'blur',
|
||||||
|
'el-input-number': 'blur',
|
||||||
|
'el-select': 'change',
|
||||||
|
'el-radio-group': 'change',
|
||||||
|
'el-checkbox-group': 'change',
|
||||||
|
'el-cascader': 'change',
|
||||||
|
'el-time-picker': 'change',
|
||||||
|
'el-date-picker': 'change',
|
||||||
|
'el-rate': 'change',
|
||||||
|
'el-upload': 'change'
|
||||||
|
}
|
||||||
|
|
||||||
|
const layouts = {
|
||||||
|
colFormItem(h, scheme) {
|
||||||
|
const config = scheme.__config__
|
||||||
|
const listeners = buildListeners.call(this, scheme)
|
||||||
|
|
||||||
|
let labelWidth = config.labelWidth ? `${config.labelWidth}px` : null
|
||||||
|
if (config.showLabel === false) labelWidth = '0'
|
||||||
|
return (
|
||||||
|
<el-col span={config.span}>
|
||||||
|
<el-form-item label-width={labelWidth} prop={scheme.__vModel__}
|
||||||
|
label={config.showLabel ? config.label : ''}>
|
||||||
|
<render conf={scheme} on={listeners} />
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
rowFormItem(h, scheme) {
|
||||||
|
let child = renderChildren.apply(this, arguments)
|
||||||
|
if (scheme.type === 'flex') {
|
||||||
|
child = <el-row type={scheme.type} justify={scheme.justify} align={scheme.align}>
|
||||||
|
{child}
|
||||||
|
</el-row>
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<el-col span={scheme.span}>
|
||||||
|
<el-row gutter={scheme.gutter}>
|
||||||
|
{child}
|
||||||
|
</el-row>
|
||||||
|
</el-col>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderFrom(h) {
|
||||||
|
const { formConfCopy } = this
|
||||||
|
|
||||||
|
return (
|
||||||
|
<el-row gutter={formConfCopy.gutter}>
|
||||||
|
<el-form
|
||||||
|
size={formConfCopy.size}
|
||||||
|
label-position={formConfCopy.labelPosition}
|
||||||
|
disabled={formConfCopy.disabled}
|
||||||
|
label-width={`${formConfCopy.labelWidth}px`}
|
||||||
|
ref={formConfCopy.formRef}
|
||||||
|
// model不能直接赋值 https://github.com/vuejs/jsx/issues/49#issuecomment-472013664
|
||||||
|
props={{ model: this[formConfCopy.formModel] }}
|
||||||
|
rules={this[formConfCopy.formRules]}
|
||||||
|
>
|
||||||
|
{renderFormItem.call(this, h, formConfCopy.fields)}
|
||||||
|
{formConfCopy.formBtns && formBtns.call(this, h)}
|
||||||
|
</el-form>
|
||||||
|
</el-row>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formBtns(h) {
|
||||||
|
return <el-col>
|
||||||
|
<el-form-item size="large">
|
||||||
|
<el-button type="primary" onClick={this.submitForm}>提交</el-button>
|
||||||
|
<el-button onClick={this.resetForm}>重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderFormItem(h, elementList) {
|
||||||
|
return elementList.map(scheme => {
|
||||||
|
const config = scheme.__config__
|
||||||
|
const layout = layouts[config.layout]
|
||||||
|
|
||||||
|
if (layout) {
|
||||||
|
return layout.call(this, h, scheme)
|
||||||
|
}
|
||||||
|
throw new Error(`没有与${config.layout}匹配的layout`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderChildren(h, scheme) {
|
||||||
|
const config = scheme.__config__
|
||||||
|
if (!Array.isArray(config.children)) return null
|
||||||
|
return renderFormItem.call(this, h, config.children)
|
||||||
|
}
|
||||||
|
|
||||||
|
function setValue(event, config, scheme) {
|
||||||
|
this.$set(config, 'defaultValue', event)
|
||||||
|
this.$set(this[this.formConf.formModel], scheme.__vModel__, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildListeners(scheme) {
|
||||||
|
const config = scheme.__config__
|
||||||
|
const methods = this.formConf.__methods__ || {}
|
||||||
|
const listeners = {}
|
||||||
|
|
||||||
|
// 给__methods__中的方法绑定this和event
|
||||||
|
Object.keys(methods).forEach(key => {
|
||||||
|
listeners[key] = event => methods[key].call(this, event)
|
||||||
|
})
|
||||||
|
// 响应 render.js 中的 vModel $emit('input', val)
|
||||||
|
listeners.input = event => setValue.call(this, event, config, scheme)
|
||||||
|
|
||||||
|
return listeners
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
render
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
formConf: {
|
||||||
|
type: Object,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
const data = {
|
||||||
|
formConfCopy: deepClone(this.formConf),
|
||||||
|
[this.formConf.formModel]: {},
|
||||||
|
[this.formConf.formRules]: {}
|
||||||
|
}
|
||||||
|
this.initFormData(data.formConfCopy.fields, data[this.formConf.formModel])
|
||||||
|
this.buildRules(data.formConfCopy.fields, data[this.formConf.formRules])
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
initFormData(componentList, formData) {
|
||||||
|
componentList.forEach(cur => {
|
||||||
|
this.buildOptionMethod(cur)
|
||||||
|
const config = cur.__config__;
|
||||||
|
if (cur.__vModel__) {
|
||||||
|
formData[cur.__vModel__] = config.defaultValue;
|
||||||
|
// 初始化文件列表
|
||||||
|
if (cur.action && config.defaultValue) {
|
||||||
|
cur['file-list'] = config.defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cur.action) {
|
||||||
|
cur['headers'] = {
|
||||||
|
Authorization: "Bearer " + getToken(),
|
||||||
|
}
|
||||||
|
cur['on-success'] = (res, file, fileList) => {
|
||||||
|
formData[cur.__vModel__] = fileList;
|
||||||
|
if (res.code === 200 && fileList) {
|
||||||
|
config.defaultValue = fileList;
|
||||||
|
config.defaultValue.forEach(val => {
|
||||||
|
val.url = file.response.data.url;
|
||||||
|
val.ossId = file.response.data.ossId;
|
||||||
|
val.response = null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// 点击文件列表中已上传的文件时的钩子
|
||||||
|
cur['on-preview'] = (file) => {
|
||||||
|
this.$download.oss(file.ossId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (config.children) {
|
||||||
|
this.initFormData(config.children, formData);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// 特殊处理的 Option
|
||||||
|
buildOptionMethod(scheme) {
|
||||||
|
const config = scheme.__config__;
|
||||||
|
if (config && config.tag === 'el-cascader') {
|
||||||
|
if (config.dataType === 'dynamic') {
|
||||||
|
this.$axios({
|
||||||
|
method: config.method,
|
||||||
|
url: config.url
|
||||||
|
}).then(resp => {
|
||||||
|
var { data } = resp
|
||||||
|
scheme[config.dataConsumer] = data[config.dataKey]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
buildRules(componentList, rules) {
|
||||||
|
componentList.forEach(cur => {
|
||||||
|
const config = cur.__config__
|
||||||
|
if (Array.isArray(config.regList)) {
|
||||||
|
if (config.required) {
|
||||||
|
const required = { required: config.required, message: cur.placeholder }
|
||||||
|
if (Array.isArray(config.defaultValue)) {
|
||||||
|
required.type = 'array'
|
||||||
|
required.message = `请至少选择一个${config.label}`
|
||||||
|
}
|
||||||
|
required.message === undefined && (required.message = `${config.label}不能为空`)
|
||||||
|
config.regList.push(required)
|
||||||
|
}
|
||||||
|
rules[cur.__vModel__] = config.regList.map(item => {
|
||||||
|
item.pattern && (item.pattern = eval(item.pattern))
|
||||||
|
item.trigger = ruleTrigger && ruleTrigger[config.tag]
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (config.children) this.buildRules(config.children, rules)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
resetForm() {
|
||||||
|
this.formConfCopy = deepClone(this.formConf)
|
||||||
|
this.$refs[this.formConf.formRef].resetFields()
|
||||||
|
},
|
||||||
|
submitForm() {
|
||||||
|
this.$refs[this.formConf.formRef].validate(valid => {
|
||||||
|
if (!valid) return false
|
||||||
|
const params = {
|
||||||
|
formData: this.formConfCopy,
|
||||||
|
valData: this[this.formConf.formModel]
|
||||||
|
}
|
||||||
|
this.$emit('submit', params)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// 传值给父组件
|
||||||
|
getData(){
|
||||||
|
debugger
|
||||||
|
this.$emit('getData', this[this.formConf.formModel])
|
||||||
|
// this.$emit('getData',this.formConfCopy)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
render(h) {
|
||||||
|
return renderFrom.call(this, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
276
src/utils/generator/render.jsx
Normal file
276
src/utils/generator/render.jsx
Normal file
@ -0,0 +1,276 @@
|
|||||||
|
import { deepClone } from "@/utils/index";
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElColorPicker,
|
||||||
|
ElDatePicker,
|
||||||
|
ElInput,
|
||||||
|
ElInputNumber,
|
||||||
|
ElRate,
|
||||||
|
ElRow,
|
||||||
|
ElSelect,
|
||||||
|
ElSlider,
|
||||||
|
ElSwitch,
|
||||||
|
ElTimePicker,
|
||||||
|
ElUpload,
|
||||||
|
} from "element-plus";
|
||||||
|
import { h, defineComponent } from "vue";
|
||||||
|
// import "element-plus/es/components/input";
|
||||||
|
const formComponentsMap = {
|
||||||
|
"el-input": ElInput,
|
||||||
|
"el-input-number": ElInputNumber,
|
||||||
|
"el-switch": ElSwitch,
|
||||||
|
"el-select": ElSelect,
|
||||||
|
"el-time-picker": ElTimePicker,
|
||||||
|
"el-color-picker": ElColorPicker,
|
||||||
|
"el-date-picker": ElDatePicker,
|
||||||
|
"el-button": ElButton,
|
||||||
|
"el-row": ElRow,
|
||||||
|
"el-slider": ElSlider,
|
||||||
|
"el-rate": ElRate,
|
||||||
|
"el-upload": ElUpload,
|
||||||
|
};
|
||||||
|
|
||||||
|
const componentChild = {};
|
||||||
|
/**
|
||||||
|
* 将./slots中的文件挂载到对象componentChild上
|
||||||
|
* 文件名为key,对应JSON配置中的__config__.tag
|
||||||
|
* 文件内容为value,解析JSON配置中的__slot__
|
||||||
|
*/
|
||||||
|
const slotsFiles = import.meta.glob("./slots/*.jsx", { eager: true });
|
||||||
|
// const slotsFiles = require.context("./slots", false, /\.js$/);
|
||||||
|
const keys = Object.keys(slotsFiles) || [];
|
||||||
|
keys.forEach((key) => {
|
||||||
|
const tag = key.replace(/^\.\/slots\/(.*)\.\w+$/, "$1");
|
||||||
|
componentChild[tag] = slotsFiles[key].default;
|
||||||
|
});
|
||||||
|
|
||||||
|
function vModel(dataObject, defaultValue) {
|
||||||
|
dataObject.props.value = defaultValue;
|
||||||
|
// dataObject.onInput = (val) => {
|
||||||
|
// this.$emit("input", val);
|
||||||
|
// };
|
||||||
|
dataObject.on.input = (val) => {
|
||||||
|
console.log(val, "input");
|
||||||
|
this.$emit("input", val);
|
||||||
|
};
|
||||||
|
dataObject.on.change = (val) => {
|
||||||
|
console.log(val, "change");
|
||||||
|
this.$emit("input", val);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function mountSlotFiles(h, confClone, children) {
|
||||||
|
const childObjs = componentChild[confClone.__config__.tag];
|
||||||
|
if (childObjs) {
|
||||||
|
Object.keys(childObjs).forEach((key) => {
|
||||||
|
const childFunc = childObjs[key];
|
||||||
|
if (confClone.__slot__ && confClone.__slot__[key]) {
|
||||||
|
children.push(childFunc(h, confClone, key));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitEvents(confClone) {
|
||||||
|
["on", "nativeOn"].forEach((attr) => {
|
||||||
|
const eventKeyList = Object.keys(confClone[attr] || {});
|
||||||
|
eventKeyList.forEach((key) => {
|
||||||
|
const val = confClone[attr][key];
|
||||||
|
if (typeof val === "string") {
|
||||||
|
confClone[attr][key] = (event) => this.$emit(val, event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildDataObject(confClone, dataObject) {
|
||||||
|
Object.keys(confClone).forEach((key) => {
|
||||||
|
const val = confClone[key];
|
||||||
|
if (key === "__vModel__") {
|
||||||
|
vModel.call(this, dataObject, confClone.__config__.defaultValue);
|
||||||
|
} else if (dataObject[key] !== undefined) {
|
||||||
|
if (
|
||||||
|
dataObject[key] === null ||
|
||||||
|
dataObject[key] instanceof RegExp ||
|
||||||
|
["boolean", "string", "number", "function"].includes(
|
||||||
|
typeof dataObject[key]
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
dataObject[key] = val;
|
||||||
|
} else if (Array.isArray(dataObject[key])) {
|
||||||
|
dataObject[key] = [...dataObject[key], ...val];
|
||||||
|
} else {
|
||||||
|
dataObject[key] = { ...dataObject[key], ...val };
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dataObject.attrs[key] = val;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 清理属性
|
||||||
|
clearAttrs(dataObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearAttrs(dataObject) {
|
||||||
|
delete dataObject.attrs.__config__;
|
||||||
|
delete dataObject.attrs.__slot__;
|
||||||
|
delete dataObject.attrs.__methods__;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeDataObject() {
|
||||||
|
// 深入数据对象:
|
||||||
|
// https://cn.vuejs.org/v2/guide/render-function.html#%E6%B7%B1%E5%85%A5%E6%95%B0%E6%8D%AE%E5%AF%B9%E8%B1%A1
|
||||||
|
return {
|
||||||
|
class: {},
|
||||||
|
attrs: {},
|
||||||
|
props: {},
|
||||||
|
domProps: {},
|
||||||
|
nativeOn: {},
|
||||||
|
on: {},
|
||||||
|
style: {},
|
||||||
|
directives: [],
|
||||||
|
scopedSlots: {},
|
||||||
|
slot: null,
|
||||||
|
key: null,
|
||||||
|
ref: null,
|
||||||
|
refInFor: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// export default defineComponent({
|
||||||
|
// name: "render",
|
||||||
|
// props: {
|
||||||
|
// conf: {
|
||||||
|
// type: Object,
|
||||||
|
// required: true,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// setup(props, ctx) {
|
||||||
|
// console.log(props);
|
||||||
|
// console.log(ctx);
|
||||||
|
// const dataObject = makeDataObject();
|
||||||
|
// const confClone = deepClone(props.conf);
|
||||||
|
// const children = [ctx.slots.default] || [];
|
||||||
|
// // 如果slots文件夹存在与当前tag同名的文件,则执行文件中的代码
|
||||||
|
// mountSlotFiles.call(this, h, confClone, children);
|
||||||
|
|
||||||
|
// // 将字符串类型的事件,发送为消息
|
||||||
|
// emitEvents.call(this, confClone);
|
||||||
|
|
||||||
|
// // 将json表单配置转化为vue render可以识别的 “数据对象(dataObject)”
|
||||||
|
// buildDataObject.call(this, confClone, dataObject);
|
||||||
|
// const Tag = props.conf.__config__.tag;
|
||||||
|
// return <Tag></Tag>;
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: "render",
|
||||||
|
props: {
|
||||||
|
conf: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: ["input"],
|
||||||
|
render() {
|
||||||
|
const dataObject = makeDataObject();
|
||||||
|
const confClone = deepClone(this.conf);
|
||||||
|
|
||||||
|
// const children = [this.$slots.default] || [];
|
||||||
|
const children = [];
|
||||||
|
// 如果slots文件夹存在与当前tag同名的文件,则执行文件中的代码
|
||||||
|
mountSlotFiles(h, confClone, children);
|
||||||
|
|
||||||
|
// 将字符串类型的事件,发送为消息
|
||||||
|
emitEvents.call(this, confClone);
|
||||||
|
|
||||||
|
// 将json表单配置转化为vue render可以识别的 “数据对象(dataObject)”
|
||||||
|
buildDataObject.call(this, confClone, dataObject);
|
||||||
|
console.log(dataObject);
|
||||||
|
// return () => h("el-input", dataObject.attrs);
|
||||||
|
|
||||||
|
const Tag = formComponentsMap[this.conf.__config__.tag];
|
||||||
|
return (
|
||||||
|
<Tag
|
||||||
|
{...dataObject.attrs}
|
||||||
|
on={dataObject.on}
|
||||||
|
modelValue={confClone.__config__.defaultValue}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{tag == "el-input" ? (
|
||||||
|
<el-input
|
||||||
|
{...dataObject.attrs}
|
||||||
|
on={dataObject.on}
|
||||||
|
modelValue={confClone.__config__.defaultValue}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</el-input>
|
||||||
|
) : tag == "el-input-number" ? (
|
||||||
|
<el-input-number
|
||||||
|
{...dataObject.attrs}
|
||||||
|
on={dataObject.on}
|
||||||
|
modelValue={confClone.__config__.defaultValue}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</el-input-number>
|
||||||
|
) : tag == "el-slider" ? (
|
||||||
|
<el-slider
|
||||||
|
{...dataObject.attrs}
|
||||||
|
on={dataObject.on}
|
||||||
|
modelValue={confClone.__config__.defaultValue}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</el-slider>
|
||||||
|
) : tag == "el-time-picker" ? (
|
||||||
|
<el-date-picker
|
||||||
|
type="datetimerange"
|
||||||
|
on={dataObject.on}
|
||||||
|
modelValue={confClone.__config__.defaultValue}
|
||||||
|
/>
|
||||||
|
) : tag === "el-switch" ? (
|
||||||
|
<el-switch
|
||||||
|
{...dataObject.attrs}
|
||||||
|
on={dataObject.on}
|
||||||
|
modelValue={confClone.__config__.defaultValue}
|
||||||
|
></el-switch>
|
||||||
|
) : tag === "el-color-picker" ? (
|
||||||
|
<el-color-picker
|
||||||
|
{...dataObject.attrs}
|
||||||
|
on={dataObject.on}
|
||||||
|
modelValue={confClone.__config__.defaultValue}
|
||||||
|
></el-color-picker>
|
||||||
|
) : tag === "el-button" ? (
|
||||||
|
<el-button
|
||||||
|
{...dataObject.attrs}
|
||||||
|
on={dataObject.on}
|
||||||
|
modelValue={confClone.__config__.defaultValue}
|
||||||
|
>
|
||||||
|
{children[1]}
|
||||||
|
</el-button>
|
||||||
|
) : tag === "el-select" ? (
|
||||||
|
<el-select
|
||||||
|
{...dataObject.attrs}
|
||||||
|
on={dataObject.on}
|
||||||
|
modelValue={confClone.__config__.defaultValue}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</el-select>
|
||||||
|
) : tag === "el-date-picker" ? (
|
||||||
|
<el-date-picker
|
||||||
|
{...dataObject.attrs}
|
||||||
|
on={dataObject.on}
|
||||||
|
modelValue={confClone.__config__.defaultValue}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</el-date-picker>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
16
src/utils/generator/ruleTrigger.js
Normal file
16
src/utils/generator/ruleTrigger.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* 用于生成表单校验,指定正则规则的触发方式。
|
||||||
|
* 未在此处声明无触发方式的组件将不生成rule!!
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
'el-input': 'blur',
|
||||||
|
'el-input-number': 'blur',
|
||||||
|
'el-select': 'change',
|
||||||
|
'el-radio-group': 'change',
|
||||||
|
'el-checkbox-group': 'change',
|
||||||
|
'el-cascader': 'change',
|
||||||
|
'el-time-picker': 'change',
|
||||||
|
'el-date-picker': 'change',
|
||||||
|
'el-rate': 'change',
|
||||||
|
tinymce: 'blur'
|
||||||
|
}
|
||||||
5
src/utils/generator/slots/el-button.jsx
Normal file
5
src/utils/generator/slots/el-button.jsx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
default(h, conf, key) {
|
||||||
|
return conf.__slot__[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/utils/generator/slots/el-checkbox-group.jsx
Normal file
13
src/utils/generator/slots/el-checkbox-group.jsx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
export default {
|
||||||
|
options(h, conf, key) {
|
||||||
|
const list = []
|
||||||
|
conf.__slot__.options.forEach(item => {
|
||||||
|
if (conf.__config__.optionType === 'button') {
|
||||||
|
list.push(<el-checkbox-button label={item.value}>{item.label}</el-checkbox-button>)
|
||||||
|
} else {
|
||||||
|
list.push(<el-checkbox label={item.value} border={conf.border}>{item.label}</el-checkbox>)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/utils/generator/slots/el-input.jsx
Normal file
8
src/utils/generator/slots/el-input.jsx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export default {
|
||||||
|
prepend(h, conf, key) {
|
||||||
|
return <template slot="prepend">{conf.__slot__[key]}</template>
|
||||||
|
},
|
||||||
|
append(h, conf, key) {
|
||||||
|
return <template slot="append">{conf.__slot__[key]}</template>
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/utils/generator/slots/el-radio-group.jsx
Normal file
13
src/utils/generator/slots/el-radio-group.jsx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
export default {
|
||||||
|
options(h, conf, key) {
|
||||||
|
const list = []
|
||||||
|
conf.__slot__.options.forEach(item => {
|
||||||
|
if (conf.__config__.optionType === 'button') {
|
||||||
|
list.push(<el-radio-button label={item.value}>{item.label}</el-radio-button>)
|
||||||
|
} else {
|
||||||
|
list.push(<el-radio label={item.value} border={conf.border}>{item.label}</el-radio>)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/utils/generator/slots/el-select.jsx
Normal file
15
src/utils/generator/slots/el-select.jsx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
export default {
|
||||||
|
options(h, conf, key) {
|
||||||
|
const list = [];
|
||||||
|
conf.__slot__.options.forEach((item) => {
|
||||||
|
list.push(
|
||||||
|
<el-option
|
||||||
|
label={item.label}
|
||||||
|
value={item.value}
|
||||||
|
disabled={item.disabled}
|
||||||
|
></el-option>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return list;
|
||||||
|
},
|
||||||
|
};
|
||||||
17
src/utils/generator/slots/el-upload.jsx
Normal file
17
src/utils/generator/slots/el-upload.jsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export default {
|
||||||
|
'list-type': (h, conf, key) => {
|
||||||
|
const list = []
|
||||||
|
const config = conf.__config__
|
||||||
|
if (conf['list-type'] === 'picture-card') {
|
||||||
|
list.push(<i class="el-icon-plus"></i>)
|
||||||
|
} else {
|
||||||
|
list.push(<el-button size="small" type="primary" icon="el-icon-upload">{config.buttonText}</el-button>)
|
||||||
|
}
|
||||||
|
if (config.showTip) {
|
||||||
|
list.push(
|
||||||
|
<div slot="tip" class="el-upload__tip">只能上传不超过 {config.fileSize}{config.sizeUnit} 的{conf.accept}文件</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/utils/loadBeautifier.js
Normal file
28
src/utils/loadBeautifier.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import loadScript from "./loadScript";
|
||||||
|
import ELEMENT from "element-plus";
|
||||||
|
import pluginsConfig from "./pluginsConfig";
|
||||||
|
|
||||||
|
let beautifierObj;
|
||||||
|
|
||||||
|
export default function loadBeautifier(cb) {
|
||||||
|
const { beautifierUrl } = pluginsConfig;
|
||||||
|
if (beautifierObj) {
|
||||||
|
cb(beautifierObj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loading = ELEMENT.Loading.service({
|
||||||
|
fullscreen: true,
|
||||||
|
lock: true,
|
||||||
|
text: "格式化资源加载中...",
|
||||||
|
spinner: "el-icon-loading",
|
||||||
|
background: "rgba(255, 255, 255, 0.5)",
|
||||||
|
});
|
||||||
|
|
||||||
|
loadScript(beautifierUrl, () => {
|
||||||
|
loading.close();
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
beautifierObj = beautifier;
|
||||||
|
cb(beautifierObj);
|
||||||
|
});
|
||||||
|
}
|
||||||
40
src/utils/loadMonaco.js
Normal file
40
src/utils/loadMonaco.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import loadScript from "./loadScript";
|
||||||
|
import ELEMENT from "element-plus";
|
||||||
|
import pluginsConfig from "./pluginsConfig";
|
||||||
|
|
||||||
|
// monaco-editor单例
|
||||||
|
let monacoEidtor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态加载monaco-editor cdn资源
|
||||||
|
* @param {Function} cb 回调,必填
|
||||||
|
*/
|
||||||
|
export default function loadMonaco(cb) {
|
||||||
|
if (monacoEidtor) {
|
||||||
|
cb(monacoEidtor);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { monacoEditorUrl: vs } = pluginsConfig;
|
||||||
|
|
||||||
|
// 使用element ui实现加载提示
|
||||||
|
const loading = ELEMENT.Loading.service({
|
||||||
|
fullscreen: true,
|
||||||
|
lock: true,
|
||||||
|
text: "编辑器资源初始化中...",
|
||||||
|
spinner: "el-icon-loading",
|
||||||
|
background: "rgba(255, 255, 255, 0.5)",
|
||||||
|
});
|
||||||
|
|
||||||
|
!window.require && (window.require = {});
|
||||||
|
!window.require.paths && (window.require.paths = {});
|
||||||
|
window.require.paths.vs = vs;
|
||||||
|
|
||||||
|
loadScript(`${vs}/loader.js`, () => {
|
||||||
|
window.require(["vs/editor/editor.main"], () => {
|
||||||
|
loading.close();
|
||||||
|
monacoEidtor = window.monaco;
|
||||||
|
cb(monacoEidtor);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
60
src/utils/loadScript.js
Normal file
60
src/utils/loadScript.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
const callbacks = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载一个远程脚本
|
||||||
|
* @param {String} src 一个远程脚本
|
||||||
|
* @param {Function} callback 回调
|
||||||
|
*/
|
||||||
|
function loadScript(src, callback) {
|
||||||
|
const existingScript = document.getElementById(src)
|
||||||
|
const cb = callback || (() => {})
|
||||||
|
if (!existingScript) {
|
||||||
|
callbacks[src] = []
|
||||||
|
const $script = document.createElement('script')
|
||||||
|
$script.src = src
|
||||||
|
$script.id = src
|
||||||
|
$script.async = 1
|
||||||
|
document.body.appendChild($script)
|
||||||
|
const onEnd = 'onload' in $script ? stdOnEnd.bind($script) : ieOnEnd.bind($script)
|
||||||
|
onEnd($script)
|
||||||
|
}
|
||||||
|
|
||||||
|
callbacks[src].push(cb)
|
||||||
|
|
||||||
|
function stdOnEnd(script) {
|
||||||
|
script.onload = () => {
|
||||||
|
this.onerror = this.onload = null
|
||||||
|
callbacks[src].forEach(item => {
|
||||||
|
item(null, script)
|
||||||
|
})
|
||||||
|
delete callbacks[src]
|
||||||
|
}
|
||||||
|
script.onerror = () => {
|
||||||
|
this.onerror = this.onload = null
|
||||||
|
cb(new Error(`Failed to load ${src}`), script)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ieOnEnd(script) {
|
||||||
|
script.onreadystatechange = () => {
|
||||||
|
if (this.readyState !== 'complete' && this.readyState !== 'loaded') return
|
||||||
|
this.onreadystatechange = null
|
||||||
|
callbacks[src].forEach(item => {
|
||||||
|
item(null, script)
|
||||||
|
})
|
||||||
|
delete callbacks[src]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 顺序加载一组远程脚本
|
||||||
|
* @param {Array} list 一组远程脚本
|
||||||
|
* @param {Function} cb 回调
|
||||||
|
*/
|
||||||
|
export function loadScriptQueue(list, cb) {
|
||||||
|
const first = list.shift()
|
||||||
|
list.length ? loadScript(first, () => loadScriptQueue(list, cb)) : loadScript(first, cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default loadScript
|
||||||
17
src/utils/pluginsConfig.js
Normal file
17
src/utils/pluginsConfig.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
const CDN = "https://lib.baomitu.com/"; // CDN Homepage: https://cdn.baomitu.com/
|
||||||
|
const publicPath = import.meta.env.VITE_APP_BASE_API;
|
||||||
|
|
||||||
|
function splicingPluginUrl(PluginName, version, fileName) {
|
||||||
|
return `${CDN}${PluginName}/${version}/${fileName}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
beautifierUrl: splicingPluginUrl(
|
||||||
|
"js-beautify",
|
||||||
|
"1.13.5",
|
||||||
|
"beautifier.min.js"
|
||||||
|
),
|
||||||
|
// monacoEditorUrl: splicingPluginUrl('monaco-editor', '0.19.3', 'min/vs'), // 使用 monaco-editor CDN 链接
|
||||||
|
monacoEditorUrl: `${publicPath}libs/monaco-editor/vs`, // 使用 monaco-editor 本地代码
|
||||||
|
tinymceUrl: splicingPluginUrl("tinymce", "5.7.0", "tinymce.min.js"),
|
||||||
|
};
|
||||||
106
src/views/tool/build/CodeTypeDialog.vue
Normal file
106
src/views/tool/build/CodeTypeDialog.vue
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<el-dialog
|
||||||
|
v-bind="$attrs"
|
||||||
|
width="500px"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:modal-append-to-body="false"
|
||||||
|
v-on="$listeners"
|
||||||
|
@open="onOpen"
|
||||||
|
@close="onClose"
|
||||||
|
>
|
||||||
|
<el-row :gutter="15">
|
||||||
|
<el-form
|
||||||
|
ref="elForm"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
size="medium"
|
||||||
|
label-width="100px"
|
||||||
|
>
|
||||||
|
<el-col :span="24">
|
||||||
|
<el-form-item label="生成类型" prop="type">
|
||||||
|
<el-radio-group v-model="formData.type">
|
||||||
|
<el-radio-button
|
||||||
|
v-for="(item, index) in typeOptions"
|
||||||
|
:key="index"
|
||||||
|
:label="item.value"
|
||||||
|
:disabled="item.disabled"
|
||||||
|
>
|
||||||
|
{{ item.label }}
|
||||||
|
</el-radio-button>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item v-if="showFileName" label="文件名" prop="fileName">
|
||||||
|
<el-input v-model="formData.fileName" placeholder="请输入文件名" clearable />
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</el-form>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<div slot="footer">
|
||||||
|
<el-button @click="close">
|
||||||
|
取消
|
||||||
|
</el-button>
|
||||||
|
<el-button type="primary" @click="handleConfirm">
|
||||||
|
确定
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: ['showFileName'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
formData: {
|
||||||
|
fileName: undefined,
|
||||||
|
type: 'file'
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
fileName: [{
|
||||||
|
required: true,
|
||||||
|
message: '请输入文件名',
|
||||||
|
trigger: 'blur'
|
||||||
|
}],
|
||||||
|
type: [{
|
||||||
|
required: true,
|
||||||
|
message: '生成类型不能为空',
|
||||||
|
trigger: 'change'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
typeOptions: [{
|
||||||
|
label: '页面',
|
||||||
|
value: 'file'
|
||||||
|
}, {
|
||||||
|
label: '弹窗',
|
||||||
|
value: 'dialog'
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
},
|
||||||
|
watch: {},
|
||||||
|
mounted() {},
|
||||||
|
methods: {
|
||||||
|
onOpen() {
|
||||||
|
if (this.showFileName) {
|
||||||
|
this.formData.fileName = `${+new Date()}.vue`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onClose() {
|
||||||
|
},
|
||||||
|
close(e) {
|
||||||
|
this.$emit('update:visible', false)
|
||||||
|
},
|
||||||
|
handleConfirm() {
|
||||||
|
this.$refs.elForm.validate(valid => {
|
||||||
|
if (!valid) return
|
||||||
|
this.$emit('confirm', { ...this.formData })
|
||||||
|
this.close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
225
src/views/tool/build/DraggableItem.jsx
Normal file
225
src/views/tool/build/DraggableItem.jsx
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
import draggable from "vuedraggable";
|
||||||
|
import render from "@/utils/generator/render";
|
||||||
|
import { defineComponent } from "vue";
|
||||||
|
import { CopyDocument, Delete } from "@element-plus/icons-vue";
|
||||||
|
|
||||||
|
const components = {
|
||||||
|
itemBtns(currentItem, index, list) {
|
||||||
|
const { onCopyItem, onDeleteItem } = this.$attrs;
|
||||||
|
return [
|
||||||
|
<span
|
||||||
|
class="drawing-item-copy"
|
||||||
|
title="复制"
|
||||||
|
onClick={(event) => {
|
||||||
|
onCopyItem(currentItem, list);
|
||||||
|
event.stopPropagation();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<el-icon>
|
||||||
|
<CopyDocument />
|
||||||
|
</el-icon>
|
||||||
|
</span>,
|
||||||
|
<span
|
||||||
|
class="drawing-item-delete"
|
||||||
|
title="删除"
|
||||||
|
onClick={(event) => {
|
||||||
|
onDeleteItem(index, list);
|
||||||
|
event.stopPropagation();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<el-icon>
|
||||||
|
<Delete />
|
||||||
|
</el-icon>
|
||||||
|
</span>,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const layouts = {
|
||||||
|
colFormItem(
|
||||||
|
// h,
|
||||||
|
currentItem,
|
||||||
|
index,
|
||||||
|
list
|
||||||
|
) {
|
||||||
|
const { onActiveItem } = this.$attrs;
|
||||||
|
const config = currentItem.__config__;
|
||||||
|
console.log(arguments, "argu");
|
||||||
|
const child = renderChildren.apply(this, arguments);
|
||||||
|
let className =
|
||||||
|
this.activeId === config.formId
|
||||||
|
? "drawing-item active-from-item"
|
||||||
|
: "drawing-item";
|
||||||
|
if (this.formConf.unFocusedComponentBorder)
|
||||||
|
className += " unfocus-bordered";
|
||||||
|
let labelWidth = config.labelWidth ? `${config.labelWidth}px` : null;
|
||||||
|
if (config.showLabel === false) labelWidth = "0";
|
||||||
|
console.log(child);
|
||||||
|
return (
|
||||||
|
<el-col
|
||||||
|
span={config.span}
|
||||||
|
class={className}
|
||||||
|
onClick={(event) => {
|
||||||
|
onActiveItem(currentItem);
|
||||||
|
event.stopPropagation();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<el-form-item
|
||||||
|
label-width={labelWidth}
|
||||||
|
label={config.showLabel ? config.label : ""}
|
||||||
|
required={config.required}
|
||||||
|
>
|
||||||
|
<render
|
||||||
|
key={config.renderKey}
|
||||||
|
conf={currentItem}
|
||||||
|
onInput={(event) => {
|
||||||
|
console.log(event);
|
||||||
|
// console.log(this.currentItem.__config__.defaultValue);
|
||||||
|
// this.$set(config, "defaultValue", event);
|
||||||
|
// console.log(this.currentItem.__config__.defaultValue);
|
||||||
|
this.currentItem.__config__.defaultValue = event;
|
||||||
|
// config.defaultValue = event;
|
||||||
|
// config.defaultValue = event;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{child}
|
||||||
|
</render>
|
||||||
|
</el-form-item>
|
||||||
|
{components.itemBtns.apply(this, arguments)}
|
||||||
|
</el-col>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
rowFormItem(
|
||||||
|
// h,
|
||||||
|
currentItem,
|
||||||
|
index,
|
||||||
|
list
|
||||||
|
) {
|
||||||
|
const { onActiveItem } = this.$attrs;
|
||||||
|
const config = currentItem.__config__;
|
||||||
|
const className =
|
||||||
|
this.activeId === config.formId
|
||||||
|
? "drawing-row-item active-from-item"
|
||||||
|
: "drawing-row-item";
|
||||||
|
let child = renderChildren.apply(this, arguments);
|
||||||
|
|
||||||
|
if (currentItem.type === "flex") {
|
||||||
|
child = (
|
||||||
|
<el-row
|
||||||
|
type={currentItem.type}
|
||||||
|
justify={currentItem.justify}
|
||||||
|
align={currentItem.align}
|
||||||
|
>
|
||||||
|
{child}
|
||||||
|
</el-row>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
console.log(child, "row");
|
||||||
|
return (
|
||||||
|
<el-col span={config.span}>
|
||||||
|
<el-row
|
||||||
|
gutter={config.gutter}
|
||||||
|
class={className}
|
||||||
|
onClick={(event) => {
|
||||||
|
onActiveItem(currentItem);
|
||||||
|
event.stopPropagation();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span class="component-name">{config.componentName}</span>
|
||||||
|
<draggable
|
||||||
|
list={config.children || []}
|
||||||
|
animation={340}
|
||||||
|
group="componentsGroup"
|
||||||
|
class="drag-wrapper"
|
||||||
|
item-key="id"
|
||||||
|
draggable
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
item: () => child,
|
||||||
|
}}
|
||||||
|
</draggable>
|
||||||
|
{components.itemBtns.apply(this, arguments)}
|
||||||
|
</el-row>
|
||||||
|
</el-col>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
raw(
|
||||||
|
// h,
|
||||||
|
currentItem,
|
||||||
|
index,
|
||||||
|
list
|
||||||
|
) {
|
||||||
|
const config = currentItem.__config__;
|
||||||
|
const child = renderChildren.apply(this, arguments);
|
||||||
|
return (
|
||||||
|
<render
|
||||||
|
key={config.renderKey}
|
||||||
|
conf={currentItem}
|
||||||
|
onInput={(event) => {
|
||||||
|
// this.$set(config, "defaultValue", event);
|
||||||
|
// console.log(this.currentItem.__config__.defaultValue);
|
||||||
|
this.currentItem.__config__.defaultValue = event;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{child}
|
||||||
|
</render>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function renderChildren(
|
||||||
|
// h,
|
||||||
|
currentItem,
|
||||||
|
index,
|
||||||
|
list
|
||||||
|
) {
|
||||||
|
const config = currentItem.__config__;
|
||||||
|
console.log(config, "config");
|
||||||
|
if (!Array.isArray(config.children)) return null;
|
||||||
|
return config.children.map((el, i) => {
|
||||||
|
const layout = layouts[el.__config__.layout];
|
||||||
|
if (layout) {
|
||||||
|
return layout.call(
|
||||||
|
this,
|
||||||
|
// h,
|
||||||
|
el,
|
||||||
|
i,
|
||||||
|
config.children
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return layoutIsNotFound.call(this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function layoutIsNotFound() {
|
||||||
|
throw new Error(`没有与${this.currentItem.__config__.layout}匹配的layout`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: "DraggableItem",
|
||||||
|
components: {
|
||||||
|
render,
|
||||||
|
draggable,
|
||||||
|
},
|
||||||
|
props: ["currentItem", "index", "drawingList", "activeId", "formConf"],
|
||||||
|
methods: {
|
||||||
|
set(val) {
|
||||||
|
this.currentItem.__config__.defaultValue = val;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
// console.log(this.currentItem.__config__.layout);
|
||||||
|
const layout = layouts[this.currentItem.__config__.layout];
|
||||||
|
// console.log(this.currentItem);
|
||||||
|
console.log(layout, "layout");
|
||||||
|
if (layout) {
|
||||||
|
return layout.call(
|
||||||
|
this,
|
||||||
|
// h,
|
||||||
|
this.currentItem,
|
||||||
|
this.index,
|
||||||
|
this.drawingList
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return layoutIsNotFound.call(this);
|
||||||
|
},
|
||||||
|
});
|
||||||
354
src/views/tool/build/FormDrawer.vue
Normal file
354
src/views/tool/build/FormDrawer.vue
Normal file
@ -0,0 +1,354 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<el-drawer
|
||||||
|
v-bind="$attrs"
|
||||||
|
v-on="$listeners"
|
||||||
|
@opened="onOpen"
|
||||||
|
@close="onClose"
|
||||||
|
>
|
||||||
|
<div style="height: 100%">
|
||||||
|
<el-row style="height: 100%; overflow: auto">
|
||||||
|
<el-col :md="24" :lg="12" class="left-editor">
|
||||||
|
<div class="setting" title="资源引用" @click="showResource">
|
||||||
|
<el-badge :is-dot="!!resources.length" class="item">
|
||||||
|
<i class="el-icon-setting" />
|
||||||
|
</el-badge>
|
||||||
|
</div>
|
||||||
|
<el-tabs v-model="activeTab" type="card" class="editor-tabs">
|
||||||
|
<el-tab-pane name="html">
|
||||||
|
<span slot="label">
|
||||||
|
<i v-if="activeTab === 'html'" class="el-icon-edit" />
|
||||||
|
<i v-else class="el-icon-document" />
|
||||||
|
template
|
||||||
|
</span>
|
||||||
|
</el-tab-pane>
|
||||||
|
<el-tab-pane name="js">
|
||||||
|
<span slot="label">
|
||||||
|
<i v-if="activeTab === 'js'" class="el-icon-edit" />
|
||||||
|
<i v-else class="el-icon-document" />
|
||||||
|
script
|
||||||
|
</span>
|
||||||
|
</el-tab-pane>
|
||||||
|
<el-tab-pane name="css">
|
||||||
|
<span slot="label">
|
||||||
|
<i v-if="activeTab === 'css'" class="el-icon-edit" />
|
||||||
|
<i v-else class="el-icon-document" />
|
||||||
|
css
|
||||||
|
</span>
|
||||||
|
</el-tab-pane>
|
||||||
|
</el-tabs>
|
||||||
|
<div
|
||||||
|
v-show="activeTab === 'html'"
|
||||||
|
id="editorHtml"
|
||||||
|
class="tab-editor"
|
||||||
|
/>
|
||||||
|
<div v-show="activeTab === 'js'" id="editorJs" class="tab-editor" />
|
||||||
|
<div
|
||||||
|
v-show="activeTab === 'css'"
|
||||||
|
id="editorCss"
|
||||||
|
class="tab-editor"
|
||||||
|
/>
|
||||||
|
</el-col>
|
||||||
|
<el-col :md="24" :lg="12" class="right-preview">
|
||||||
|
<div class="action-bar" :style="{ 'text-align': 'left' }">
|
||||||
|
<span class="bar-btn" @click="runCode">
|
||||||
|
<i class="el-icon-refresh" />
|
||||||
|
刷新
|
||||||
|
</span>
|
||||||
|
<span class="bar-btn" @click="exportFile">
|
||||||
|
<i class="el-icon-download" />
|
||||||
|
导出vue文件
|
||||||
|
</span>
|
||||||
|
<span ref="copyBtn" class="bar-btn copy-btn">
|
||||||
|
<i class="el-icon-document-copy" />
|
||||||
|
复制代码
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="bar-btn delete-btn"
|
||||||
|
@click="$emit('update:visible', false)"
|
||||||
|
>
|
||||||
|
<i class="el-icon-circle-close" />
|
||||||
|
关闭
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<iframe
|
||||||
|
v-show="isIframeLoaded"
|
||||||
|
ref="previewPage"
|
||||||
|
class="result-wrapper"
|
||||||
|
frameborder="0"
|
||||||
|
src="/preview.html"
|
||||||
|
@load="iframeLoad"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-show="!isIframeLoaded"
|
||||||
|
v-loading="true"
|
||||||
|
class="result-wrapper"
|
||||||
|
/>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</div>
|
||||||
|
</el-drawer>
|
||||||
|
<resource-dialog
|
||||||
|
:visible.sync="resourceVisible"
|
||||||
|
:origin-resource="resources"
|
||||||
|
@save="setResource"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import { parse } from "@babel/parser";
|
||||||
|
import ClipboardJS from "clipboard";
|
||||||
|
import { saveAs } from "file-saver";
|
||||||
|
import {
|
||||||
|
makeUpHtml,
|
||||||
|
vueTemplate,
|
||||||
|
vueScript,
|
||||||
|
cssStyle,
|
||||||
|
} from "@/utils/generator/html";
|
||||||
|
import { makeUpJs } from "@/utils/generator/js";
|
||||||
|
import { makeUpCss } from "@/utils/generator/css";
|
||||||
|
import { exportDefault, beautifierConf, titleCase } from "@/utils/index";
|
||||||
|
import ResourceDialog from "./ResourceDialog";
|
||||||
|
import loadMonaco from "@/utils/loadMonaco";
|
||||||
|
import loadBeautifier from "@/utils/loadBeautifier";
|
||||||
|
|
||||||
|
const editorObj = {
|
||||||
|
html: null,
|
||||||
|
js: null,
|
||||||
|
css: null,
|
||||||
|
};
|
||||||
|
const mode = {
|
||||||
|
html: "html",
|
||||||
|
js: "javascript",
|
||||||
|
css: "css",
|
||||||
|
};
|
||||||
|
let beautifier;
|
||||||
|
let monaco;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: { ResourceDialog },
|
||||||
|
props: ["formData", "generateConf"],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
activeTab: "html",
|
||||||
|
htmlCode: "",
|
||||||
|
jsCode: "",
|
||||||
|
cssCode: "",
|
||||||
|
codeFrame: "",
|
||||||
|
isIframeLoaded: false,
|
||||||
|
isInitcode: false, // 保证open后两个异步只执行一次runcode
|
||||||
|
isRefreshCode: false, // 每次打开都需要重新刷新代码
|
||||||
|
resourceVisible: false,
|
||||||
|
scripts: [],
|
||||||
|
links: [],
|
||||||
|
monaco: null,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
resources() {
|
||||||
|
return this.scripts.concat(this.links);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {},
|
||||||
|
created() {},
|
||||||
|
mounted() {
|
||||||
|
window.addEventListener("keydown", this.preventDefaultSave);
|
||||||
|
const clipboard = new ClipboardJS(".copy-btn", {
|
||||||
|
text: (trigger) => {
|
||||||
|
const codeStr = this.generateCode();
|
||||||
|
this.$notify({
|
||||||
|
title: "成功",
|
||||||
|
message: "代码已复制到剪切板,可粘贴。",
|
||||||
|
type: "success",
|
||||||
|
});
|
||||||
|
return codeStr;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
clipboard.on("error", (e) => {
|
||||||
|
this.$message.error("代码复制失败");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
window.removeEventListener("keydown", this.preventDefaultSave);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
preventDefaultSave(e) {
|
||||||
|
if (e.key === "s" && (e.metaKey || e.ctrlKey)) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onOpen() {
|
||||||
|
const { type } = this.generateConf;
|
||||||
|
this.htmlCode = makeUpHtml(this.formData, type);
|
||||||
|
this.jsCode = makeUpJs(this.formData, type);
|
||||||
|
this.cssCode = makeUpCss(this.formData);
|
||||||
|
|
||||||
|
loadBeautifier((btf) => {
|
||||||
|
beautifier = btf;
|
||||||
|
this.htmlCode = beautifier.html(this.htmlCode, beautifierConf.html);
|
||||||
|
this.jsCode = beautifier.js(this.jsCode, beautifierConf.js);
|
||||||
|
this.cssCode = beautifier.css(this.cssCode, beautifierConf.html);
|
||||||
|
|
||||||
|
loadMonaco((val) => {
|
||||||
|
monaco = val;
|
||||||
|
this.setEditorValue("editorHtml", "html", this.htmlCode);
|
||||||
|
this.setEditorValue("editorJs", "js", this.jsCode);
|
||||||
|
this.setEditorValue("editorCss", "css", this.cssCode);
|
||||||
|
if (!this.isInitcode) {
|
||||||
|
this.isRefreshCode = true;
|
||||||
|
this.isIframeLoaded && (this.isInitcode = true) && this.runCode();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onClose() {
|
||||||
|
this.isInitcode = false;
|
||||||
|
this.isRefreshCode = false;
|
||||||
|
},
|
||||||
|
iframeLoad() {
|
||||||
|
if (!this.isInitcode) {
|
||||||
|
this.isIframeLoaded = true;
|
||||||
|
this.isRefreshCode && (this.isInitcode = true) && this.runCode();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setEditorValue(id, type, codeStr) {
|
||||||
|
if (editorObj[type]) {
|
||||||
|
editorObj[type].setValue(codeStr);
|
||||||
|
} else {
|
||||||
|
editorObj[type] = monaco.editor.create(document.getElementById(id), {
|
||||||
|
value: codeStr,
|
||||||
|
theme: "vs-dark",
|
||||||
|
language: mode[type],
|
||||||
|
automaticLayout: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// ctrl + s 刷新
|
||||||
|
editorObj[type].onKeyDown((e) => {
|
||||||
|
if (e.keyCode === 49 && (e.metaKey || e.ctrlKey)) {
|
||||||
|
this.runCode();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
runCode() {
|
||||||
|
const jsCodeStr = editorObj.js.getValue();
|
||||||
|
try {
|
||||||
|
const ast = parse(jsCodeStr, { sourceType: "module" });
|
||||||
|
const astBody = ast.program.body;
|
||||||
|
if (astBody.length > 1) {
|
||||||
|
this.$confirm(
|
||||||
|
"js格式不能识别,仅支持修改export default的对象内容",
|
||||||
|
"提示",
|
||||||
|
{
|
||||||
|
type: "warning",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (astBody[0].type === "ExportDefaultDeclaration") {
|
||||||
|
const postData = {
|
||||||
|
type: "refreshFrame",
|
||||||
|
data: {
|
||||||
|
generateConf: this.generateConf,
|
||||||
|
html: editorObj.html.getValue(),
|
||||||
|
js: jsCodeStr.replace(exportDefault, ""),
|
||||||
|
css: editorObj.css.getValue(),
|
||||||
|
scripts: this.scripts,
|
||||||
|
links: this.links,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$refs.previewPage.contentWindow.postMessage(
|
||||||
|
postData,
|
||||||
|
location.origin
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.$message.error("请使用export default");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
this.$message.error(`js错误:${err}`);
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
generateCode() {
|
||||||
|
const html = vueTemplate(editorObj.html.getValue());
|
||||||
|
const script = vueScript(editorObj.js.getValue());
|
||||||
|
const css = cssStyle(editorObj.css.getValue());
|
||||||
|
return beautifier.html(html + script + css, beautifierConf.html);
|
||||||
|
},
|
||||||
|
exportFile() {
|
||||||
|
this.$prompt("文件名:", "导出文件", {
|
||||||
|
inputValue: `${+new Date()}.vue`,
|
||||||
|
closeOnClickModal: false,
|
||||||
|
inputPlaceholder: "请输入文件名",
|
||||||
|
}).then(({ value }) => {
|
||||||
|
if (!value) value = `${+new Date()}.vue`;
|
||||||
|
const codeStr = this.generateCode();
|
||||||
|
const blob = new Blob([codeStr], { type: "text/plain;charset=utf-8" });
|
||||||
|
saveAs(blob, value);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
showResource() {
|
||||||
|
this.resourceVisible = true;
|
||||||
|
},
|
||||||
|
setResource(arr) {
|
||||||
|
const scripts = [];
|
||||||
|
const links = [];
|
||||||
|
if (Array.isArray(arr)) {
|
||||||
|
arr.forEach((item) => {
|
||||||
|
if (item.endsWith(".css")) {
|
||||||
|
links.push(item);
|
||||||
|
} else {
|
||||||
|
scripts.push(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.scripts = scripts;
|
||||||
|
this.links = links;
|
||||||
|
} else {
|
||||||
|
this.scripts = [];
|
||||||
|
this.links = [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import "@/assets/styles/mixin.scss";
|
||||||
|
.tab-editor {
|
||||||
|
position: absolute;
|
||||||
|
top: 33px;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
.left-editor {
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
background: #1e1e1e;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.setting {
|
||||||
|
position: absolute;
|
||||||
|
right: 15px;
|
||||||
|
top: 3px;
|
||||||
|
color: #a9f122;
|
||||||
|
font-size: 18px;
|
||||||
|
cursor: pointer;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
.right-preview {
|
||||||
|
height: 100%;
|
||||||
|
.result-wrapper {
|
||||||
|
height: calc(100vh - 33px);
|
||||||
|
width: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
padding: 12px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@include action-bar;
|
||||||
|
:deep(.el-drawer__header) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
128
src/views/tool/build/IconsDialog.vue
Normal file
128
src/views/tool/build/IconsDialog.vue
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
<template>
|
||||||
|
<div class="icon-dialog">
|
||||||
|
<el-dialog
|
||||||
|
v-bind="$attrs"
|
||||||
|
width="980px"
|
||||||
|
:modal-append-to-body="false"
|
||||||
|
@open="onOpen"
|
||||||
|
@close="onClose"
|
||||||
|
>
|
||||||
|
<!-- v-on="$listeners" -->
|
||||||
|
<div slot="title">
|
||||||
|
选择图标
|
||||||
|
<el-input
|
||||||
|
v-model="key"
|
||||||
|
size="mini"
|
||||||
|
:style="{ width: '260px' }"
|
||||||
|
placeholder="请输入图标名称"
|
||||||
|
prefix-icon="el-icon-search"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<ul class="icon-ul">
|
||||||
|
<li
|
||||||
|
v-for="icon in iconList"
|
||||||
|
:key="icon"
|
||||||
|
:class="active === icon ? 'active-item' : ''"
|
||||||
|
@click="onSelect(icon)"
|
||||||
|
>
|
||||||
|
<i :class="icon" />
|
||||||
|
<div>{{ icon }}</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- <script setup>
|
||||||
|
</script> -->
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import iconList from "@/utils/generator/icon.json";
|
||||||
|
|
||||||
|
const originList = iconList.map((name) => `el-icon-${name}`);
|
||||||
|
|
||||||
|
export default {
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: ["current"],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
iconList: originList,
|
||||||
|
active: null,
|
||||||
|
key: "",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
emits: ["select", "update:visible"],
|
||||||
|
watch: {
|
||||||
|
key(val) {
|
||||||
|
if (val) {
|
||||||
|
this.iconList = originList.filter((name) => name.indexOf(val) > -1);
|
||||||
|
} else {
|
||||||
|
this.iconList = originList;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onOpen() {
|
||||||
|
this.active = this.current;
|
||||||
|
this.key = "";
|
||||||
|
},
|
||||||
|
onClose() {},
|
||||||
|
onSelect(icon) {
|
||||||
|
this.active = icon;
|
||||||
|
emit("select", icon);
|
||||||
|
emit("update:visible", false);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.icon-ul {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-size: 0;
|
||||||
|
li {
|
||||||
|
list-style-type: none;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 14px;
|
||||||
|
display: inline-block;
|
||||||
|
width: 16.66%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
height: 108px;
|
||||||
|
padding: 15px 6px 6px 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
overflow: hidden;
|
||||||
|
&:hover {
|
||||||
|
background: #f2f2f2;
|
||||||
|
}
|
||||||
|
&.active-item {
|
||||||
|
background: #e1f3fb;
|
||||||
|
color: #7a6df0;
|
||||||
|
}
|
||||||
|
> i {
|
||||||
|
font-size: 30px;
|
||||||
|
line-height: 50px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.icon-dialog {
|
||||||
|
:deep(.el-dialog) {
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 0;
|
||||||
|
margin-top: 4vh !important;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
max-height: 92vh;
|
||||||
|
overflow: hidden;
|
||||||
|
box-sizing: border-box;
|
||||||
|
.el-dialog__header {
|
||||||
|
padding-top: 14px;
|
||||||
|
}
|
||||||
|
.el-dialog__body {
|
||||||
|
margin: 0 20px 20px 20px;
|
||||||
|
padding: 0;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
156
src/views/tool/build/JsonDrawer.vue
Normal file
156
src/views/tool/build/JsonDrawer.vue
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<el-drawer v-bind="$attrs" @opened="onOpen" @close="onClose">
|
||||||
|
<div class="action-bar" :style="{ 'text-align': 'left' }">
|
||||||
|
<span class="bar-btn" @click="refresh">
|
||||||
|
<i class="el-icon-refresh" />
|
||||||
|
刷新
|
||||||
|
</span>
|
||||||
|
<span ref="copyBtn" class="bar-btn copy-json-btn">
|
||||||
|
<i class="el-icon-document-copy" />
|
||||||
|
复制JSON
|
||||||
|
</span>
|
||||||
|
<span class="bar-btn" @click="exportJsonFile">
|
||||||
|
<i class="el-icon-download" />
|
||||||
|
导出JSON文件
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="bar-btn delete-btn"
|
||||||
|
@click="$emit('update:visible', false)"
|
||||||
|
>
|
||||||
|
<i class="el-icon-circle-close" />
|
||||||
|
关闭
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div id="editorJson" class="json-editor" />
|
||||||
|
</el-drawer>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="JsonDrawer">
|
||||||
|
import { beautifierConf } from "@/utils/index";
|
||||||
|
import ClipboardJS from "clipboard";
|
||||||
|
import { saveAs } from "file-saver";
|
||||||
|
import loadMonaco from "@/utils/loadMonaco";
|
||||||
|
import loadBeautifier from "@/utils/loadBeautifier";
|
||||||
|
import { defineComponent, onBeforeUnmount, onMounted, toRefs } from "vue";
|
||||||
|
|
||||||
|
let beautifier;
|
||||||
|
let monaco;
|
||||||
|
|
||||||
|
const props = defineComponent({
|
||||||
|
jsonStr: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { jsonStr } = toRefs(props);
|
||||||
|
const beautifierJson = ref("");
|
||||||
|
const preventDefaultSave = (e) => {
|
||||||
|
if (e.key === "s" && (e.metaKey || e.ctrlKey)) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const onOpen = () => {
|
||||||
|
loadBeautifier((btf) => {
|
||||||
|
beautifier = btf;
|
||||||
|
beautifierJson.value = beautifier.js(jsonStr.value, beautifierConf.js);
|
||||||
|
|
||||||
|
loadMonaco((val) => {
|
||||||
|
monaco = val;
|
||||||
|
setEditorValue("editorJson", this.beautifierJson);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const onClose = () => {};
|
||||||
|
const setEditorValue = (id, codeStr) => {
|
||||||
|
if (jsonEditor.value) {
|
||||||
|
jsonEditor.value.setValue(codeStr);
|
||||||
|
} else {
|
||||||
|
jsonEditor.value = monaco.editor.create(document.getElementById(id), {
|
||||||
|
value: codeStr,
|
||||||
|
theme: "vs-dark",
|
||||||
|
language: "json",
|
||||||
|
automaticLayout: true,
|
||||||
|
});
|
||||||
|
// ctrl + s 刷新
|
||||||
|
jsonEditor.value.onKeyDown((e) => {
|
||||||
|
if (e.keyCode === 49 && (e.metaKey || e.ctrlKey)) {
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const exportJsonFile = () => {
|
||||||
|
this.$prompt("文件名:", "导出文件", {
|
||||||
|
inputValue: `${+new Date()}.json`,
|
||||||
|
closeOnClickModal: false,
|
||||||
|
inputPlaceholder: "请输入文件名",
|
||||||
|
}).then(({ value }) => {
|
||||||
|
if (!value) value = `${+new Date()}.json`;
|
||||||
|
const codeStr = this.jsonEditor.getValue();
|
||||||
|
const blob = new Blob([codeStr], { type: "text/plain;charset=utf-8" });
|
||||||
|
saveAs(blob, value);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const refresh = () => {
|
||||||
|
try {
|
||||||
|
this.$emit("refresh", JSON.parse(this.jsonEditor.getValue()));
|
||||||
|
} catch (error) {
|
||||||
|
this.$notify({
|
||||||
|
title: "错误",
|
||||||
|
message: "JSON格式错误,请检查",
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
window.addEventListener("keydown", preventDefaultSave);
|
||||||
|
const clipboard = new ClipboardJS(".copy-json-btn", {
|
||||||
|
text: (trigger) => {
|
||||||
|
this.$notify({
|
||||||
|
title: "成功",
|
||||||
|
message: "代码已复制到剪切板,可粘贴。",
|
||||||
|
type: "success",
|
||||||
|
});
|
||||||
|
return this.beautifierJson;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
clipboard.on("error", (e) => {
|
||||||
|
this.$message.error("代码复制失败");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener("keydown", preventDefaultSave);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- <script>
|
||||||
|
export default {
|
||||||
|
components: {},
|
||||||
|
props: {},
|
||||||
|
data() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
computed: {},
|
||||||
|
watch: {},
|
||||||
|
created() {},
|
||||||
|
mounted() {},
|
||||||
|
beforeDestroy() {},
|
||||||
|
methods: {},
|
||||||
|
};
|
||||||
|
</script> -->
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import "@/assets/styles/mixin.scss";
|
||||||
|
|
||||||
|
::v-deep .el-drawer__header {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
// @include action-bar;
|
||||||
|
|
||||||
|
.json-editor {
|
||||||
|
height: calc(100vh - 33px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
116
src/views/tool/build/ResourceDialog.vue
Normal file
116
src/views/tool/build/ResourceDialog.vue
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<el-dialog
|
||||||
|
v-bind="$attrs"
|
||||||
|
title="外部资源引用"
|
||||||
|
width="600px"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
v-on="$listeners"
|
||||||
|
@open="onOpen"
|
||||||
|
@close="onClose"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
v-for="(item, index) in resources"
|
||||||
|
:key="index"
|
||||||
|
v-model="resources[index]"
|
||||||
|
class="url-item"
|
||||||
|
placeholder="请输入 css 或 js 资源路径"
|
||||||
|
prefix-icon="el-icon-link"
|
||||||
|
clearable
|
||||||
|
>
|
||||||
|
<el-button
|
||||||
|
slot="append"
|
||||||
|
icon="el-icon-delete"
|
||||||
|
@click="deleteOne(index)"
|
||||||
|
/>
|
||||||
|
</el-input>
|
||||||
|
<el-button-group class="add-item">
|
||||||
|
<el-button
|
||||||
|
plain
|
||||||
|
@click="addOne('https://lib.baomitu.com/jquery/1.8.3/jquery.min.js')"
|
||||||
|
>
|
||||||
|
jQuery1.8.3
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
plain
|
||||||
|
@click="addOne('https://unpkg.com/http-vue-loader')"
|
||||||
|
>
|
||||||
|
http-vue-loader
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
icon="el-icon-circle-plus-outline"
|
||||||
|
plain
|
||||||
|
@click="addOne('')"
|
||||||
|
>
|
||||||
|
添加其他
|
||||||
|
</el-button>
|
||||||
|
</el-button-group>
|
||||||
|
<div slot="footer">
|
||||||
|
<el-button @click="close">
|
||||||
|
取消
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
@click="handelConfirm"
|
||||||
|
>
|
||||||
|
确定
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import { deepClone } from '@/utils/index'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {},
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: ['originResource'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
resources: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {},
|
||||||
|
watch: {},
|
||||||
|
created() {},
|
||||||
|
mounted() {},
|
||||||
|
methods: {
|
||||||
|
onOpen() {
|
||||||
|
this.resources = this.originResource.length ? deepClone(this.originResource) : ['']
|
||||||
|
},
|
||||||
|
onClose() {
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.$emit('update:visible', false)
|
||||||
|
},
|
||||||
|
handelConfirm() {
|
||||||
|
const results = this.resources.filter(item => !!item) || []
|
||||||
|
this.$emit('save', results)
|
||||||
|
this.close()
|
||||||
|
if (results.length) {
|
||||||
|
this.resources = results
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deleteOne(index) {
|
||||||
|
this.resources.splice(index, 1)
|
||||||
|
},
|
||||||
|
addOne(url) {
|
||||||
|
if (this.resources.indexOf(url) > -1) {
|
||||||
|
this.$message('资源已存在')
|
||||||
|
} else {
|
||||||
|
this.resources.push(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.add-item{
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
.url-item{
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
1441
src/views/tool/build/RightPanel.vue
Normal file
1441
src/views/tool/build/RightPanel.vue
Normal file
File diff suppressed because it is too large
Load Diff
127
src/views/tool/build/TreeNodeDialog.vue
Normal file
127
src/views/tool/build/TreeNodeDialog.vue
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<el-dialog
|
||||||
|
v-bind="$attrs"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:modal-append-to-body="false"
|
||||||
|
@open="onOpen"
|
||||||
|
@close="onClose"
|
||||||
|
>
|
||||||
|
<!-- v-on="$listeners" -->
|
||||||
|
<el-row :gutter="0">
|
||||||
|
<el-form
|
||||||
|
ref="elForm"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
size="small"
|
||||||
|
label-width="100px"
|
||||||
|
>
|
||||||
|
<el-col :span="24">
|
||||||
|
<el-form-item label="选项名" prop="label">
|
||||||
|
<el-input
|
||||||
|
v-model="formData.label"
|
||||||
|
placeholder="请输入选项名"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="24">
|
||||||
|
<el-form-item label="选项值" prop="value">
|
||||||
|
<el-input
|
||||||
|
v-model="formData.value"
|
||||||
|
placeholder="请输入选项值"
|
||||||
|
clearable
|
||||||
|
>
|
||||||
|
<el-select
|
||||||
|
slot="append"
|
||||||
|
v-model="dataType"
|
||||||
|
:style="{ width: '100px' }"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="(item, index) in dataTypeOptions"
|
||||||
|
:key="index"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
:disabled="item.disabled"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-input>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</el-form>
|
||||||
|
</el-row>
|
||||||
|
<div slot="footer">
|
||||||
|
<el-button type="primary" @click="handleConfirm"> 确定 </el-button>
|
||||||
|
<el-button @click="close"> 取消 </el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { isNumberStr } from "@/utils/index";
|
||||||
|
import { reactive, ref, toRefs, watch } from "vue";
|
||||||
|
const emit = defineEmits(["update:visible", "commit"]);
|
||||||
|
const id = ref(100);
|
||||||
|
const dataType = ref("string");
|
||||||
|
let inheritAttrs = false;
|
||||||
|
const dataTypeOptions = ref([
|
||||||
|
{
|
||||||
|
label: "字符串",
|
||||||
|
value: "string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "数字",
|
||||||
|
value: "number",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
const data = reactive({
|
||||||
|
formData: {
|
||||||
|
label: undefined,
|
||||||
|
value: undefined,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
label: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: "请输入选项名",
|
||||||
|
trigger: "blur",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: "请输入选项值",
|
||||||
|
trigger: "blur",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { rules, formData } = toRefs(data);
|
||||||
|
|
||||||
|
const onOpen = () => {
|
||||||
|
formData.value = {
|
||||||
|
label: undefined,
|
||||||
|
value: undefined,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const onClose = () => {};
|
||||||
|
const close = () => {
|
||||||
|
emit("update:visible", false);
|
||||||
|
};
|
||||||
|
const handleConfirm = () => {
|
||||||
|
this.$refs.elForm.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
if (dataType.value === "number") {
|
||||||
|
formData.value.value = parseFloat(formData.value.value);
|
||||||
|
}
|
||||||
|
formData.value.id = id.value++;
|
||||||
|
emit("commit", formData.value);
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(formData.value, (val) => {
|
||||||
|
dataType.value = isNumberStr(val) ? "number" : "string";
|
||||||
|
});
|
||||||
|
</script>
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,27 +1,27 @@
|
|||||||
import { defineConfig, loadEnv } from 'vite'
|
import { defineConfig, loadEnv } from "vite";
|
||||||
import path from 'path'
|
import path from "path";
|
||||||
import createVitePlugins from './vite/plugins'
|
import createVitePlugins from "./vite/plugins";
|
||||||
|
// import vueJsx from "@vitejs/plugin-vue-jsx";
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig(({ mode, command }) => {
|
export default defineConfig(({ mode, command }) => {
|
||||||
const env = loadEnv(mode, process.cwd())
|
const env = loadEnv(mode, process.cwd());
|
||||||
const { VITE_APP_ENV } = env
|
const { VITE_APP_ENV } = env;
|
||||||
return {
|
return {
|
||||||
// 部署生产环境和开发环境下的URL。
|
// 部署生产环境和开发环境下的URL。
|
||||||
// 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
|
// 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
|
||||||
// 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
|
// 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
|
||||||
base: VITE_APP_ENV === 'production' ? '/' : '/',
|
base: VITE_APP_ENV === "production" ? "/" : "/",
|
||||||
plugins: createVitePlugins(env, command === 'build'),
|
plugins: createVitePlugins(env, command === "build"),
|
||||||
resolve: {
|
resolve: {
|
||||||
// https://cn.vitejs.dev/config/#resolve-alias
|
// https://cn.vitejs.dev/config/#resolve-alias
|
||||||
alias: {
|
alias: {
|
||||||
// 设置路径
|
// 设置路径
|
||||||
'~': path.resolve(__dirname, './'),
|
"~": path.resolve(__dirname, "./"),
|
||||||
// 设置别名
|
// 设置别名
|
||||||
'@': path.resolve(__dirname, './src')
|
"@": path.resolve(__dirname, "./src"),
|
||||||
},
|
},
|
||||||
// https://cn.vitejs.dev/config/#resolve-extensions
|
// https://cn.vitejs.dev/config/#resolve-extensions
|
||||||
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
|
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
|
||||||
},
|
},
|
||||||
// vite 相关配置
|
// vite 相关配置
|
||||||
server: {
|
server: {
|
||||||
@ -30,29 +30,29 @@ export default defineConfig(({ mode, command }) => {
|
|||||||
open: true,
|
open: true,
|
||||||
proxy: {
|
proxy: {
|
||||||
// https://cn.vitejs.dev/config/#server-proxy
|
// https://cn.vitejs.dev/config/#server-proxy
|
||||||
'/dev-api': {
|
"/dev-api": {
|
||||||
target: 'http://localhost:8080',
|
target: "http://vue.ruoyi.vip/prod-api",
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (p) => p.replace(/^\/dev-api/, '')
|
rewrite: (p) => p.replace(/^\/dev-api/, ""),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
//fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
|
//fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
|
||||||
css: {
|
css: {
|
||||||
postcss: {
|
postcss: {
|
||||||
plugins: [
|
plugins: [
|
||||||
{
|
{
|
||||||
postcssPlugin: 'internal:charset-removal',
|
postcssPlugin: "internal:charset-removal",
|
||||||
AtRule: {
|
AtRule: {
|
||||||
charset: (atRule) => {
|
charset: (atRule) => {
|
||||||
if (atRule.name === 'charset') {
|
if (atRule.name === "charset") {
|
||||||
atRule.remove();
|
atRule.remove();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
|
|||||||
@ -1,15 +1,21 @@
|
|||||||
import vue from '@vitejs/plugin-vue'
|
import vue from "@vitejs/plugin-vue";
|
||||||
|
|
||||||
import createAutoImport from './auto-import'
|
import createAutoImport from "./auto-import";
|
||||||
import createSvgIcon from './svg-icon'
|
import createSvgIcon from "./svg-icon";
|
||||||
import createCompression from './compression'
|
import createCompression from "./compression";
|
||||||
import createSetupExtend from './setup-extend'
|
import createSetupExtend from "./setup-extend";
|
||||||
|
import vueJsx from "@vitejs/plugin-vue-jsx";
|
||||||
|
|
||||||
export default function createVitePlugins(viteEnv, isBuild = false) {
|
export default function createVitePlugins(viteEnv, isBuild = false) {
|
||||||
const vitePlugins = [vue()]
|
const vitePlugins = [
|
||||||
vitePlugins.push(createAutoImport())
|
vue(),
|
||||||
vitePlugins.push(createSetupExtend())
|
vueJsx({
|
||||||
vitePlugins.push(createSvgIcon(isBuild))
|
transformOn: true,
|
||||||
isBuild && vitePlugins.push(...createCompression(viteEnv))
|
}),
|
||||||
return vitePlugins
|
];
|
||||||
|
vitePlugins.push(createAutoImport());
|
||||||
|
vitePlugins.push(createSetupExtend());
|
||||||
|
vitePlugins.push(createSvgIcon(isBuild));
|
||||||
|
isBuild && vitePlugins.push(...createCompression(viteEnv));
|
||||||
|
return vitePlugins;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user