低代码前端完成

This commit is contained in:
aixianling
2022-06-22 11:08:55 +08:00
parent 98762e996c
commit 834132fec2
3 changed files with 53 additions and 48 deletions

View File

@@ -9,7 +9,7 @@ let baseURLs = {
instance.defaults.baseURL = baseURLs[process.env.NODE_ENV] instance.defaults.baseURL = baseURLs[process.env.NODE_ENV]
instance.interceptors.request.use(config => { instance.interceptors.request.use(config => {
if (config.url.startsWith("/node")) { if (config.url.startsWith("/node")) {
config.baseURL = "/ns" config.baseURL = "/lns"
} else if (/\/project\/beta/.test(location.pathname)) { } else if (/\/project\/beta/.test(location.pathname)) {
config.baseURL = "/wg" config.baseURL = "/wg"
} else if (/\/project\/sass/.test(location.pathname)) { } else if (/\/project\/sass/.test(location.pathname)) {

View File

@@ -4,7 +4,7 @@
<ai-title slot="title" :title="pageTitle"/> <ai-title slot="title" :title="pageTitle"/>
<template #content> <template #content>
<el-form ref="AcForm" :model="form" size="small" label-width="120px" :rules="rules"> <el-form ref="AcForm" :model="form" size="small" label-width="120px" :rules="rules">
<el-tabs tab-position="left"> <el-tabs tab-position="left" @tab-click="handleSyncProps">
<el-tab-pane label="基本信息" lazy> <el-tab-pane label="基本信息" lazy>
<ai-card title="基本信息"> <ai-card title="基本信息">
<template #content> <template #content>
@@ -42,6 +42,7 @@
</ai-card> </ai-card>
<ai-card title="字段设置"> <ai-card title="字段设置">
<template #right> <template #right>
<el-button type="text" @click="handleAddProps">批量添加</el-button>
<el-button type="text" @click="form.props.push({})">添加</el-button> <el-button type="text" @click="form.props.push({})">添加</el-button>
</template> </template>
<template #content> <template #content>
@@ -49,7 +50,7 @@
<el-table-column v-for="col in colConfigs" :key="col.slot" v-bind="col"> <el-table-column v-for="col in colConfigs" :key="col.slot" v-bind="col">
<template slot-scope="{row}"> <template slot-scope="{row}">
<el-checkbox v-if="col.type=='checkBox'" v-model="row[col.slot]"/> <el-checkbox v-if="col.type=='checkBox'" v-model="row[col.slot]"/>
<span v-else-if="col.type=='chbShow'" v-text="row[col.slot]==1?'':''"/> <span v-else-if="col.type=='chbShow'" v-text="row[col.slot]==true?'':''"/>
<el-input v-else size="small" v-model="row[col.slot]" placeholder="请输入" clearable/> <el-input v-else size="small" v-model="row[col.slot]" placeholder="请输入" clearable/>
</template> </template>
</el-table-column> </el-table-column>
@@ -63,7 +64,7 @@
</ai-card> </ai-card>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="详情设计" lazy> <el-tab-pane label="详情设计" lazy>
<detail-layout v-bind="$props" :form="form" v-model="form.props"/> <detail-layout v-bind="$props" :form="form" v-model="form.detailConfig"/>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</el-form> </el-form>
@@ -116,7 +117,7 @@ export default {
}).then(res => { }).then(res => {
if (res?.data) { if (res?.data) {
this.form = res.data this.form = res.data
this.form.props.map(e => ({...e, isDetail: !!e.groupName})) this.handleSyncProps()
} }
}) })
}, },
@@ -135,6 +136,35 @@ export default {
} }
}) })
}, },
handleSyncProps() {
let detailPorps = this.form.detailConfig?.map(e => e.column)?.flat()?.map(e => e.prop)
this.form.props = this.form.props.map(e => ({...e, isDetail: !!detailPorps?.includes(e.prop)}))
},
handleAddProps() {
this.$prompt("请输入swagger示例JSON字符串", {
type: 'warning',
title: "批量添加字段",
dangerouslyUseHTMLString: true,
center: true,
}).then(({value}) => {
if (this.$checkJson(value)) {
Object.keys(JSON.parse(value)).map(prop => {
this.form.props.push({prop})
})
}
}).catch(() => 0)
},
$checkJson(str) {
if (typeof str == 'string') {
try {
let obj = JSON.parse(str);
return !!(typeof obj == 'object' && obj);
} catch (e) {
return false;
}
}
return false;
}
}, },
created() { created() {
this.getDetail() this.getDetail()

View File

@@ -183,7 +183,6 @@
</div> </div>
</div> </div>
</template> </template>
<div class="right-item" v-if="['select', 'date', 'time', 'input', 'datetime', 'textarea', 'rtf'].includes(currTarget.type)"> <div class="right-item" v-if="['select', 'date', 'time', 'input', 'datetime', 'textarea', 'rtf'].includes(currTarget.type)">
<div class="right-item__title no-solid"> <div class="right-item__title no-solid">
<h2>占位符</h2> <h2>占位符</h2>
@@ -425,6 +424,12 @@ export default {
} else if (this.groupIndex > -1 && this.isGroup) { } else if (this.groupIndex > -1 && this.isGroup) {
this.currTarget = this.targetList[this.groupIndex] this.currTarget = this.targetList[this.groupIndex]
} else this.currTarget = {} } else this.currTarget = {}
},
targetList: {
deep: true,
handler(v) {
this.$emit('change', v)
}
} }
}, },
computed: { computed: {
@@ -432,43 +437,17 @@ export default {
return '表单设置' return '表单设置'
}, },
propOps: v => v.form.props?.map(e => ({dictValue: e.prop, dictName: e.label})), propOps: v => v.form.props?.map(e => ({dictValue: e.prop, dictName: e.label})),
detailProps: {
set(v) {
let props = [v.map((e, i) => e.column.map((item, index) => ({
...e,
groupIndex: i,
groupName: e.groupName,
fieldDbName: item.isInit ? item.fieldDbName : (this.isUnique(item.type) ? item.type : `${item.type}${i}${index}`),
defaultValue: item.type === 'checkbox' && item.defaultValue ? item.defaultValue.join('`') : item.defaultValue,
selectValues: item.options ? item.options.map(o => o.label).join('`') : ''
})))].flat()
console.log(props)
this.$emit('change', props)
},
get() {
const init = {
type: 'group',
fieldName: '卡片',
fixedLabel: '卡片',
icon: 'iconpic',
groupName: '基础信息',
column: []
}
let arr = this.$copy(this.value),
groups = [...new Set(arr?.map(e => e.groupName))].filter(e => !!e)
this.targetList = groups?.length > 0 ? groups.map(groupName => ({
type: 'group',
fieldName: '卡片',
fixedLabel: '卡片',
icon: 'iconpic',
groupName,
column: arr.filter(e => e.groupName == groupName)
})) : [init]
return this.targetList
}
},
}, },
methods: { methods: {
initValue() {
let unwatch = this.$watch('value', (v) => {
if (this.targetList.length > 0) unwatch && unwatch()
else if (!!v) {
this.targetList = this.$copy(v)
unwatch && unwatch()
}
}, {immediate: true})
},
removeItem(j, i) { removeItem(j, i) {
this.groupIndex = -1 this.groupIndex = -1
this.activeIndex = -1 this.activeIndex = -1
@@ -502,7 +481,6 @@ export default {
value: '' value: ''
}) })
}, },
removeOptions(index) { removeOptions(index) {
const len = this.targetList[this.groupIndex].column[this.activeIndex].options.length const len = this.targetList[this.groupIndex].column[this.activeIndex].options.length
@@ -511,14 +489,12 @@ export default {
} }
this.targetList[this.groupIndex].column[this.activeIndex].options.splice(index, 1) this.targetList[this.groupIndex].column[this.activeIndex].options.splice(index, 1)
}, },
onEnd(e) { onEnd(e) {
const el = e.to.parentElement.parentElement const el = e.to.parentElement.parentElement
this.isGroup = false this.isGroup = false
this.activeIndex = e.newIndex this.activeIndex = e.newIndex
this.groupIndex = Number(el.getAttribute('data-index')) this.groupIndex = Number(el.getAttribute('data-index'))
}, },
onElEnd(e) { onElEnd(e) {
if (this.isGroup) { if (this.isGroup) {
this.groupIndex = e.newIndex this.groupIndex = e.newIndex
@@ -526,7 +502,6 @@ export default {
this.activeIndex = e.newIndex this.activeIndex = e.newIndex
} }
}, },
clone(e) { clone(e) {
if (e.type === 'group') { if (e.type === 'group') {
this.targetList.push(JSON.parse(JSON.stringify(e))) this.targetList.push(JSON.parse(JSON.stringify(e)))
@@ -563,7 +538,6 @@ export default {
this.activeIndex = this.targetList[0].column.length - 1 this.activeIndex = this.targetList[0].column.length - 1
}) })
}, },
onMove(e) { onMove(e) {
const el = e.draggedContext.element const el = e.draggedContext.element
if (el.type === 'group') { if (el.type === 'group') {
@@ -577,7 +551,6 @@ export default {
}) })
return !(list.indexOf(el.type) > -1 && ['name', 'idNumber', 'phone', 'area'].includes(el.type)); return !(list.indexOf(el.type) > -1 && ['name', 'idNumber', 'phone', 'area'].includes(el.type));
}, },
cloneComponent(e) { cloneComponent(e) {
if (e.type === 'group') { if (e.type === 'group') {
this.targetList.push(JSON.parse(JSON.stringify(e))) this.targetList.push(JSON.parse(JSON.stringify(e)))
@@ -599,7 +572,9 @@ export default {
return JSON.parse(JSON.stringify(e)) return JSON.parse(JSON.stringify(e))
} }
}, },
created() {
this.initValue()
}
} }
</script> </script>