13176889840 4 years ago
parent
commit
c48a156482
  1. 2
      src/api/index.js
  2. 786
      src/views/form/editor/index.vue

2
src/api/index.js

@ -34,7 +34,7 @@ api.interceptors.request.use(
*/ */
if (store.getters['user/isLogin']) { if (store.getters['user/isLogin']) {
request.headers.token = store.state.user.token request.headers.token = store.state.user.token
// request.headers.token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJhcHAiOiJnb3YiLCJjbGllbnQiOiJ3ZWIiLCJleHAiOjE2MzMwNTM0NTYsInVzZXJJZCI6Ijg0ODg3ZDQzMjEzN2EzMGI3YWJhYWM1MDY5ODZkNDYxIiwiaWF0IjoxNjMyNDQ4NjU2fQ.xc2Dz5yPaNLCJsQCZnBYKgTTb88PhBZ1E5g3NaqImhHOwOE4R_OAexct7FdSs6oh3Eqzf4Bw9e7mWHkAoFeroQ' // request.headers.token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJhcHAiOiJnb3YiLCJjbGllbnQiOiJ3ZWIiLCJleHAiOjE2NDk0OTQwMzQsInVzZXJJZCI6ImViY2VmN2MxYzYzYTg3YTIyNmU1OWYxZTAxNDlkMzMxIiwiaWF0IjoxNjQ4ODg5MjM0fQ.Zque4dkZDdqhqzUktp3kJ2I3FlH7q2c8ePbMCwqglVuAnfqozxnqRlXIHJF9RDVA1mSayPaZqYEeia5zztciFQ'
// request.headers.Authorization = store.state.user.token // request.headers.Authorization = store.state.user.token
} }
signRequest(request) signRequest(request)

786
src/views/form/editor/index.vue

@ -1,113 +1,128 @@
<template> <template>
<div class="form-edit-container"> <div class="form-edit-container">
<div class="left-board"> <div class="left-board">
<el-scrollbar class="left-scrollbar"> <el-scrollbar class="left-scrollbar">
<div class="components-list"> <div class="components-list">
<div v-for="(item, listIndex) in leftComponents" <div v-for="(item, listIndex) in leftComponents"
:key="listIndex"> :key="listIndex"
<div class="components-title"> >
<svg-icon name="component" /> <div class="components-title">
{{ item.title }} <svg-icon name="component" />
</div> {{ item.title }}
<draggable :clone="cloneComponent" </div>
:group="{ name: 'componentsGroup', pull: 'clone', put: false }" <draggable :clone="cloneComponent"
:list="item.list" :group="{ name: 'componentsGroup', pull: 'clone', put: false }"
:sort="false" :list="item.list"
class="components-draggable" :sort="false"
draggable=".components-item" class="components-draggable"
@end="onEnd"> draggable=".components-item"
<div v-for="(element, index) in item.list" @end="onEnd"
:key="index" >
class="components-item" <div v-for="(element, index) in item.list"
@click="addComponent(element)"> :key="index"
<div class="components-body"> class="components-item"
<svg-icon :name="element.__config__.tagIcon" /> @click="addComponent(element)"
{{ element.__config__.label }} >
<div class="components-body">
<svg-icon :name="element.__config__.tagIcon" />
{{ element.__config__.label }}
</div>
</div>
</draggable>
</div>
</div> </div>
</div> </el-scrollbar>
</draggable>
</div>
</div> </div>
</el-scrollbar> <div class="center-board">
</div> <el-scrollbar class="center-scrollbar">
<div class="center-board"> <el-row v-if="formConf"
<el-scrollbar class="center-scrollbar"> :gutter="formConf.gutter"
<el-row v-if="formConf" class="center-board-row"
:gutter="formConf.gutter" >
class="center-board-row"> <el-row align="middle"
<el-row align="middle" justify="center"
justify="center" type="flex"
type="flex"> >
<el-col class="form-head-title"> <el-col class="form-head-title">
<h4 class="form-name-text" <h4 class="form-name-text"
contenteditable="true" contenteditable="true"
@blur="(event)=>{ @blur="(event)=>{
this.formConf.title=event.target.innerText; this.formConf.title=event.target.innerText;
this.saveProjectInfo()}"> this.saveProjectInfo()}"
{{ formConf.title }} >
</h4> {{ formConf.title }}
</el-col> </h4>
</el-row> </el-col>
<el-row align="middle" </el-row>
justify="center" <el-row align="middle"
type="flex"> justify="center"
<el-col class="form-head-desc"> type="flex"
<Tinymce v-if="editDescription" >
v-model="formConf.description" <el-col class="form-head-desc">
placeholder="请输入表单描述" <Tinymce v-if="editDescription"
@blur="editDescription=false" v-model="formConf.description"
@input="saveProjectInfo" /> placeholder="请输入表单描述"
<div v-else @blur="editDescription=false"
class="form-name-text" @input="saveProjectInfo"
@click="editDescription=true" />
v-html="formConf.description" /> <div v-else
<!-- <p class="form-name-text" contenteditable="true"--> class="form-name-text"
<!-- @blur="(event)=>{--> @click="editDescription=true"
<!-- formConf.description=event.target.innerText;--> v-html="formConf.description"
<!-- this.saveProjectInfo()}">--> />
<!-- {{ formConf.description }}--> <!-- <p class="form-name-text" contenteditable="true"-->
<!-- </p>--> <!-- @blur="(event)=>{-->
</el-col> <!-- formConf.description=event.target.innerText;-->
</el-row> <!-- this.saveProjectInfo()}">-->
<el-divider class="form-head-divider" /> <!-- {{ formConf.description }}-->
<el-form :disabled="formConf.disabled" <!-- </p>-->
:label-position="formConf.labelPosition" </el-col>
:label-width="formConf.labelWidth + 'px'" </el-row>
:size="formConf.size"> <el-divider class="form-head-divider" />
<draggable :animation="340" <el-form :disabled="formConf.disabled"
:list="drawingList" :label-position="formConf.labelPosition"
class="drawing-board" :label-width="formConf.labelWidth + 'px'"
group="componentsGroup" :size="formConf.size"
@end="onItemEnd"> >
<draggable-item v-for="(item, index) in drawingList" <draggable :animation="340"
:key="item.renderKey" :list="drawingList"
:active-id="activeId" class="drawing-board"
:current-item="item" group="componentsGroup"
:drawing-list="drawingList" @end="onItemEnd"
:form-conf="formConf" >
:index="index" <draggable-item v-for="(item, index) in drawingList"
@activeItem="activeFormItem" :key="item.renderKey"
@changeLabel="changeLabel" :active-id="activeId"
@copyItem="drawingItemCopy" :current-item="item"
@deleteItem="drawingItemDelete" /> :drawing-list="drawingList"
</draggable> :form-conf="formConf"
<div v-show="!drawingList.length" :index="index"
class="empty-info"> @activeItem="activeFormItem"
<img style="width: 20%" @changeLabel="changeLabel"
src="@/assets/images/form-bg.png"> @copyItem="drawingItemCopy"
<p>从左侧拖入或点选组件进行表单设计</p> @deleteItem="drawingItemDelete"
</div> />
</el-form> </draggable>
</el-row> <div v-show="!drawingList.length"
</el-scrollbar> class="empty-info"
>
<img style="width: 20%"
src="@/assets/images/form-bg.png"
>
<p>从左侧拖入或点选组件进行表单设计</p>
</div>
</el-form>
</el-row>
</el-scrollbar>
</div>
<right-panel v-if="activeData"
:active-data="activeData"
:form-conf="formConf"
:show-field="!!drawingList.length"
@tag-change="tagChange"
@data-change="updateProjectItemInfo"
/>
</div> </div>
<right-panel v-if="activeData"
:active-data="activeData"
:form-conf="formConf"
:show-field="!!drawingList.length"
@tag-change="tagChange"
@data-change="updateProjectItemInfo" />
</div>
</template> </template>
<script> <script>
@ -116,12 +131,12 @@ import { debounce } from 'throttle-debounce'
import RightPanel from './RightPanel' import RightPanel from './RightPanel'
import { import {
assistComponents, assistComponents,
formConf, formConf,
imageComponents, imageComponents,
inputComponents, inputComponents,
personalInfoComponents, personalInfoComponents,
selectComponents selectComponents
} from '@/components/generator/config' } from '@/components/generator/config'
import { deepClone } from '@/utils' import { deepClone } from '@/utils'
import { dbDataConvertForItemJson, formItemConvertData } from '@/utils/convert' import { dbDataConvertForItemJson, formItemConvertData } from '@/utils/convert'
@ -134,292 +149,291 @@ let tempActiveData
let idGlobal let idGlobal
export default { export default {
components: { components: {
draggable, draggable,
RightPanel, RightPanel,
DraggableItem DraggableItem
}, },
data () { data() {
return { return {
idGlobal, idGlobal,
formConf: null, formConf: null,
editDescription: true, editDescription: true,
inputComponents, inputComponents,
selectComponents, selectComponents,
labelWidth: 100, labelWidth: 100,
drawingList: drawingDefalut, drawingList: drawingDefalut,
drawingData: {}, drawingData: {},
activeId: drawingDefalut.length != 0 ? drawingDefalut[0].formId : 0, activeId: drawingDefalut.length != 0 ? drawingDefalut[0].formId : 0,
formData: {}, formData: {},
dialogVisible: false, dialogVisible: false,
generateConf: null, generateConf: null,
showFileName: false, showFileName: false,
activeData: drawingDefalut ? drawingDefalut[0] : null, activeData: drawingDefalut ? drawingDefalut[0] : null,
saveDrawingListDebounce: debounce(340, saveDrawingList), saveDrawingListDebounce: debounce(340, saveDrawingList),
saveIdGlobalDebounce: debounce(340, saveIdGlobal), saveIdGlobalDebounce: debounce(340, saveIdGlobal),
projectKey: null, projectKey: null,
leftComponents: [ leftComponents: [
{ {
title: '联系人组件', title: '联系人组件',
list: personalInfoComponents list: personalInfoComponents
}, },
{ {
title: '输入型组件', title: '输入型组件',
list: inputComponents list: inputComponents
},
{
title: '图片型组件',
list: imageComponents
},
{
title: '辅助型组件',
list: assistComponents
},
{
title: '选择型组件',
list: selectComponents
}
]
}
},
computed: {},
watch: {
// eslint-disable-next-line func-names
'activeData.__config__.label': function(val, oldVal) {
if (
this.activeData.placeholder === undefined
|| !this.activeData.__config__.tag
|| oldActiveId !== this.activeId
) {
return
}
this.activeData.placeholder = this.activeData.placeholder.replace(oldVal, '') + val
}, },
{ activeId: {
title: '图片型组件', handler(val) {
list: imageComponents oldActiveId = val
},
immediate: true
}, },
{ drawingList: {
title: '辅助型组件', handler(val) {
list: assistComponents this.saveDrawingListDebounce(val, this.projectKey)
if (val.length === 0) this.idGlobal = 100
},
deep: true
}, },
{ idGlobal: {
title: '选择型组件', handler(val) {
list: selectComponents if (val) {
this.saveIdGlobalDebounce(val, this.projectKey)
}
},
immediate: true
} }
]
}
},
computed: {},
watch: {
// eslint-disable-next-line func-names
'activeData.__config__.label': function (val, oldVal) {
if (
this.activeData.placeholder === undefined
|| !this.activeData.__config__.tag
|| oldActiveId !== this.activeId
) {
return
}
this.activeData.placeholder = this.activeData.placeholder.replace(oldVal, '') + val
},
activeId: {
handler (val) {
oldActiveId = val
},
immediate: true
},
drawingList: {
handler (val) {
this.saveDrawingListDebounce(val, this.projectKey)
if (val.length === 0) this.idGlobal = 100
},
deep: true
},
idGlobal: {
handler (val) {
if (val) {
this.saveIdGlobalDebounce(val, this.projectKey)
}
},
immediate: true
}
},
mounted () {
//
this.formConf = JSON.parse(JSON.stringify(formConf))
// key
this.projectKey = this.$route.query.key
console.log('编辑')
console.log(this.projectKey)
//
this.queryProjectItems()
//
this.$api.get(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/${this.projectKey}`).then(res => {
this.formConf.title = res.data.name
this.formConf.description = res.data.describe
})
// Id
this.$api.get(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/max-form-id`, { params: { key: this.projectKey } }).then(res => {
this.idGlobal = res.data ? res.data : 100
})
},
methods: {
saveProjectInfo: debounce(430, true, function () {
this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/update`, {
'key': this.projectKey,
'name': this.formConf.title,
'describe': this.formConf.description
}).then(() => {
})
}),
updateProjectItemInfo (val) {
let data = formItemConvertData(val, this.projectKey)
this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/update`, data).then(() => {
})
}, },
deleteProjectItemInfo (val) { mounted() {
let data = formItemConvertData(val, this.projectKey)
this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/delete`, data).then(() => {
}) //
}, this.formConf = JSON.parse(JSON.stringify(formConf))
async saveProjectItemInfo (item) { // key
let isSuccess = false this.projectKey = this.$route.query.key
let params = formItemConvertData(item, this.projectKey) console.log('编辑')
console.log(params) console.log(this.projectKey)
let pItem = item //
await this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/create`, params).then(res => { this.queryProjectItems()
pItem.sort = res.data.sort //
isSuccess = true this.$api.get(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/${this.projectKey}`).then(res => {
}) this.formConf.title = res.data.name
// this.formConf.description = res.data.describe
if (item.typeId === 'PAGINATION') {
this.updatePaginationList()
}
return isSuccess
},
updatePaginationList () {
//
const length = this.drawingList.filter(item => item.typeId === 'PAGINATION').length
let curr = 1
this.drawingList.forEach((item, index) => {
if (item.typeId === 'PAGINATION') {
item.totalPageNum = length
item.currPageNum = curr++
this.$set(this.drawingList, index, item)
}
})
},
queryProjectItems () {
this.$api.get(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/list`, { params: { key: this.projectKey } }).then(res => {
this.drawingList = res.data.map(item => dbDataConvertForItemJson(item))
//
this.updatePaginationList()
})
},
activeFormItem (currentItem) {
this.activeData = currentItem
this.activeId = currentItem.__config__.formId
},
changeLabel (currentItem, value) {
console.log(currentItem)
console.log(value)
},
onEnd (obj) {
if (obj.from !== obj.to) {
this.activeData = tempActiveData
this.activeId = this.idGlobal
this.saveProjectItemInfo(tempActiveData).then(() => {
this.onItemEnd(obj)
}) })
} // Id
}, this.$api.get(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/max-form-id`, { params: { key: this.projectKey } }).then(res => {
onItemEnd (obj) { this.idGlobal = res.data ? res.data : 100
let params = { 'projectKey': this.projectKey }
if (this.drawingList[obj.newIndex - 1]) {
let sort1 = this.drawingList[obj.newIndex - 1].sort
params.beforePosition = sort1
}
if (this.drawingList[obj.newIndex + 1]) {
let sort2 = this.drawingList[obj.newIndex + 1].sort
params.afterPosition = sort2
}
params.formItemId = this.drawingList[obj.newIndex].__config__.formId
if (params.beforePosition || params.afterPosition) {
this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/sort`, params).then(res => {
this.drawingList[obj.newIndex].sort = res.data.sort
}) })
}
},
addComponent (item) {
const clone = this.cloneComponent(item)
this.saveProjectItemInfo(clone)
this.drawingList.push(clone)
this.activeFormItem(clone)
},
cloneComponent (origin) {
const clone = deepClone(origin)
const config = clone.__config__
config.span = this.formConf.span // span
this.createIdAndKey(clone)
clone.placeholder !== undefined && (clone.placeholder += config.label)
tempActiveData = clone
return tempActiveData
},
createIdAndKey (item) {
const config = item.__config__
config.formId = ++this.idGlobal
config.renderKey = `${config.formId}${+new Date()}` // renderKey
if (config.layout === 'colFormItem') {
item.__vModel__ = `field${this.idGlobal}`
} else if (config.layout === 'rowFormItem') {
config.componentName = `row${this.idGlobal}`
!Array.isArray(config.children) && (config.children = [])
delete config.label // rowFormItemlabel
}
if (Array.isArray(config.children)) {
config.children = config.children.map(childItem => this.createIdAndKey(childItem))
}
return item
}, },
empty () { methods: {
this.$confirm('确定要清空所有组件吗?', '提示', { type: 'warning' }) saveProjectInfo: debounce(430, true, function() {
.then( this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/update`, {
() => { 'key': this.projectKey,
this.drawingList = [] 'name': this.formConf.title,
this.idGlobal = 100 'describe': this.formConf.description
} }).then(() => {
)
}, })
drawingItemCopy (item, list) { }),
let clone = deepClone(item) updateProjectItemInfo(val) {
clone = this.createIdAndKey(clone) let data = formItemConvertData(val, this.projectKey)
list.push(clone) this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/update`, data).then(() => {
this.activeFormItem(clone)
this.saveProjectItemInfo(clone) })
}, },
drawingItemDelete (index, list) { deleteProjectItemInfo(val) {
let item = list[index] let data = formItemConvertData(val, this.projectKey)
list.splice(index, 1) this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/delete`, data).then(() => {
this.$nextTick(() => {
const len = this.drawingList.length })
if (len) { },
this.activeFormItem(this.drawingList[len - 1]) async saveProjectItemInfo(item) {
let isSuccess = false
let params = formItemConvertData(item, this.projectKey)
let pItem = item
await this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/create`, params).then(res => {
pItem.sort = res.data.sort
isSuccess = true
})
//
if (item.typeId === 'PAGINATION') {
this.updatePaginationList()
}
return isSuccess
},
updatePaginationList() {
//
const length = this.drawingList.filter(item => item.typeId === 'PAGINATION').length
let curr = 1
this.drawingList.forEach((item, index) => {
if (item.typeId === 'PAGINATION') {
item.totalPageNum = length
item.currPageNum = curr++
this.$set(this.drawingList, index, item)
}
})
},
queryProjectItems() {
this.$api.get(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/list`, { params: { key: this.projectKey } }).then(res => {
this.drawingList = res.data.map(item => dbDataConvertForItemJson(item))
//
this.updatePaginationList()
})
},
activeFormItem(currentItem) {
this.activeData = currentItem
this.activeId = currentItem.__config__.formId
},
changeLabel(currentItem, value) {
console.log(currentItem)
console.log(value)
},
onEnd(obj) {
if (obj.from !== obj.to) {
this.activeData = tempActiveData
this.activeId = this.idGlobal
this.saveProjectItemInfo(tempActiveData).then(() => {
this.onItemEnd(obj)
})
}
},
onItemEnd(obj) {
let params = { 'projectKey': this.projectKey }
if (this.drawingList[obj.newIndex - 1]) {
let sort1 = this.drawingList[obj.newIndex - 1].sort
params.beforePosition = sort1
}
if (this.drawingList[obj.newIndex + 1]) {
let sort2 = this.drawingList[obj.newIndex + 1].sort
params.afterPosition = sort2
}
params.formItemId = this.drawingList[obj.newIndex].__config__.formId
if (params.beforePosition || params.afterPosition) {
this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/project/item/sort`, params).then(res => {
this.drawingList[obj.newIndex].sort = res.data.sort
})
}
},
addComponent(item) {
const clone = this.cloneComponent(item)
this.saveProjectItemInfo(clone)
this.drawingList.push(clone)
this.activeFormItem(clone)
},
cloneComponent(origin) {
const clone = deepClone(origin)
const config = clone.__config__
config.span = this.formConf.span // span
this.createIdAndKey(clone)
clone.placeholder !== undefined && (clone.placeholder)
tempActiveData = clone
return tempActiveData
},
createIdAndKey(item) {
const config = item.__config__
config.formId = ++this.idGlobal
config.renderKey = `${config.formId}${+new Date()}` // renderKey
if (config.layout === 'colFormItem') {
item.__vModel__ = `field${this.idGlobal}`
} else if (config.layout === 'rowFormItem') {
config.componentName = `row${this.idGlobal}`
!Array.isArray(config.children) && (config.children = [])
delete config.label // rowFormItemlabel
}
if (Array.isArray(config.children)) {
config.children = config.children.map(childItem => this.createIdAndKey(childItem))
}
return item
},
empty() {
this.$confirm('确定要清空所有组件吗?', '提示', { type: 'warning' })
.then(
() => {
this.drawingList = []
this.idGlobal = 100
}
)
},
drawingItemCopy(item, list) {
let clone = deepClone(item)
clone = this.createIdAndKey(clone)
list.push(clone)
this.activeFormItem(clone)
this.saveProjectItemInfo(clone)
},
drawingItemDelete(index, list) {
let item = list[index]
list.splice(index, 1)
this.$nextTick(() => {
const len = this.drawingList.length
if (len) {
this.activeFormItem(this.drawingList[len - 1])
}
})
this.deleteProjectItemInfo(item)
},
tagChange(newTag) {
newTag = this.cloneComponent(newTag)
const config = newTag.__config__
newTag.__vModel__ = this.activeData.__vModel__
newTag.sort = this.activeData.sort
config.formId = this.activeId
config.span = this.activeData.__config__.span
this.activeData.__config__.tag = config.tag
this.activeData.__config__.tagIcon = config.tagIcon
this.activeData.__config__.document = config.document
this.activeData.typeId = newTag.typeId
if (typeof this.activeData.__config__.defaultValue === typeof config.defaultValue) {
config.defaultValue = this.activeData.__config__.defaultValue
}
Object.keys(newTag)
.forEach(key => {
if (this.activeData[key] !== undefined) {
newTag[key] = this.activeData[key]
}
})
this.activeData = newTag
this.updateProjectItemInfo(newTag)
this.updateDrawingList(newTag, this.drawingList)
},
updateDrawingList(newTag, list) {
const index = list.findIndex(item => item.__config__.formId === this.activeId)
if (index > -1) {
list.splice(index, 1, newTag)
} else {
list.forEach(item => {
if (Array.isArray(item.__config__.children)) this.updateDrawingList(newTag, item.__config__.children)
})
}
} }
})
this.deleteProjectItemInfo(item)
},
tagChange (newTag) {
newTag = this.cloneComponent(newTag)
const config = newTag.__config__
newTag.__vModel__ = this.activeData.__vModel__
newTag.sort = this.activeData.sort
config.formId = this.activeId
config.span = this.activeData.__config__.span
this.activeData.__config__.tag = config.tag
this.activeData.__config__.tagIcon = config.tagIcon
this.activeData.__config__.document = config.document
this.activeData.typeId = newTag.typeId
if (typeof this.activeData.__config__.defaultValue === typeof config.defaultValue) {
config.defaultValue = this.activeData.__config__.defaultValue
}
Object.keys(newTag)
.forEach(key => {
if (this.activeData[key] !== undefined) {
newTag[key] = this.activeData[key]
}
})
this.activeData = newTag
this.updateProjectItemInfo(newTag)
this.updateDrawingList(newTag, this.drawingList)
},
updateDrawingList (newTag, list) {
const index = list.findIndex(item => item.__config__.formId === this.activeId)
if (index > -1) {
list.splice(index, 1, newTag)
} else {
list.forEach(item => {
if (Array.isArray(item.__config__.children)) this.updateDrawingList(newTag, item.__config__.children)
})
}
} }
}
} }
</script> </script>

Loading…
Cancel
Save