Commit df2871ee authored by chenqikuai's avatar chenqikuai

feat: 【表现形式】添加修改表现形式、重命名

parent 4c66a0fb
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
:placeholder="levelObj.placeholder" :placeholder="levelObj.placeholder"
/> />
<div <div
v-if="wordType !== DataType.Unit" v-if="wordType !== DataType.Unit && flag !== FLAG_UPDATE"
@click="handleClickFieldType" @click="handleClickFieldType"
style="text-align:left;display:flex;justify-content:space-between;padding:16px;color:#999999;font-size:14px;" style="text-align:left;display:flex;justify-content:space-between;padding:16px;color:#999999;font-size:14px;"
> >
...@@ -57,7 +57,11 @@ ...@@ -57,7 +57,11 @@
@back="showOptions = false" @back="showOptions = false"
@confirmWordType="confirmWordType" @confirmWordType="confirmWordType"
></add-option> ></add-option>
<more-action :show.sync="showMoreAction" :menuList="menuList" @cb="callbackFromMoreAction"></more-action> <more-action
:show.sync="showMoreAction"
:menuList="menuList"
@cb="callbackFromMoreAction"
></more-action>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
...@@ -76,6 +80,11 @@ import { TEMPLATETYPE, DataType } from '@/const/enum'; ...@@ -76,6 +80,11 @@ import { TEMPLATETYPE, DataType } from '@/const/enum';
import WordItem from './WordItem.vue'; import WordItem from './WordItem.vue';
import AddOption from './AddOption.vue'; import AddOption from './AddOption.vue';
import { IData, TemplateDataItem } from '@/const/interface'; import { IData, TemplateDataItem } from '@/const/interface';
const FLAG_UPDATE = 'update';
const FLAG_BEFORE = 'before';
const FLAG_AFTER = 'after';
@Component({ @Component({
components: { components: {
WordItem, WordItem,
...@@ -91,7 +100,11 @@ export default class Add extends Vue { ...@@ -91,7 +100,11 @@ export default class Add extends Vue {
private wordType: DataType = DataType.Unit; private wordType: DataType = DataType.Unit;
private readonly DataType: any = DataType; private readonly DataType: any = DataType;
private wordName: string = ''; private wordName: string = '';
private flag: string = ''; private flag: string = '';
private FLAG_UPDATE = FLAG_UPDATE;
private isModifyForm = false;
private options: string[] = []; private options: string[] = [];
private activeName = 0; private activeName = 0;
private addOptionPropOption = [] as string[]; private addOptionPropOption = [] as string[];
...@@ -101,32 +114,51 @@ export default class Add extends Vue { ...@@ -101,32 +114,51 @@ export default class Add extends Vue {
private show: boolean = false; private show: boolean = false;
private showMoreAction: boolean = false; private showMoreAction: boolean = false;
private currentAction: {index: number; parentIndex: number} = { private currentAction: { index: number; parentIndex: number } = {
index: -1, index: -1,
parentIndex: -1, parentIndex: -1,
}; };
private menuList: any[] = [
{ get menuList() {
icon: 'zaishangtianjia', const list = [
text: '在上添加', {
callback: this.addBefore.bind(this), icon: 'zaishangtianjia2x',
}, text: '在上添加',
{ callback: this.addBefore.bind(this),
icon: 'zaixiatianjia', },
text: '在下添加', {
callback: this.addAfter.bind(this), icon: 'zaixiatianjia2x',
}, text: '在下添加',
{ callback: this.addAfter.bind(this),
icon: 'shanchu4', },
text: '删除', {
callback: this.delWord.bind(this), icon: 'shanchu2x',
}, text: '删除',
{ callback: this.delWord.bind(this),
icon: 'shanchu4', },
text: '编辑', {
callback: this.updateWord.bind(this), icon: 'zhongmingming2x',
}, text: '重命名',
]; callback: this.rename.bind(this),
},
{
isField: true,
icon: 'xiugaibianxianxingshi2x',
text: '修改表现形式',
callback: this.modifyForm.bind(this),
},
];
return list.filter((item: any) => {
if (this.currentAction.parentIndex === -1) {
// 如果是标题
return !item.isField;
} else {
// 如果是字段
return true;
}
});
}
private readonly typeObj: any = { private readonly typeObj: any = {
[DataType.Input]: '单行文本', [DataType.Input]: '单行文本',
[DataType.Image]: '图片', [DataType.Image]: '图片',
...@@ -231,6 +263,7 @@ export default class Add extends Vue { ...@@ -231,6 +263,7 @@ export default class Add extends Vue {
this.showMoreAction = true; this.showMoreAction = true;
this.currentAction = { index, parentIndex }; this.currentAction = { index, parentIndex };
} }
private resolveAction(flag: string = '') { private resolveAction(flag: string = '') {
const { index, parentIndex } = this.currentAction; const { index, parentIndex } = this.currentAction;
const wordType = parentIndex === -1 ? DataType.Unit : DataType.Input; const wordType = parentIndex === -1 ? DataType.Unit : DataType.Input;
...@@ -238,13 +271,13 @@ export default class Add extends Vue { ...@@ -238,13 +271,13 @@ export default class Add extends Vue {
this.preAddWord({ wordType, word }, flag); this.preAddWord({ wordType, word }, flag);
} }
private addBefore() { private addBefore() {
this.resolveAction('before'); this.resolveAction(FLAG_BEFORE);
} }
private addAfter() { private addAfter() {
this.resolveAction('after'); this.resolveAction(FLAG_AFTER);
} }
private updateWord() { private rename() {
this.resolveAction('update'); this.resolveAction(FLAG_UPDATE);
} }
private async delWord() { private async delWord() {
const { index, parentIndex } = this.currentAction; const { index, parentIndex } = this.currentAction;
...@@ -261,47 +294,80 @@ export default class Add extends Vue { ...@@ -261,47 +294,80 @@ export default class Add extends Vue {
return tempWords.splice(index, 1); return tempWords.splice(index, 1);
} }
private handleClickFieldType(){ // 返回当前选中的项
const clickedField = this.currentWords[this.currentAction.index] as TemplateDataItem; private getFocusedItem(parentIndex: number, index: number) {
if(this.flag === "update"){ if (parentIndex === -1) {
// 当前点击的是标题
return this.words[index];
} else {
// 当前点击的是字段
return this.words[parentIndex].data[index];
}
}
// 修改表现形式
private modifyForm() {
this.isModifyForm = true;
const clickedField = this.getFocusedItem(
this.currentAction.parentIndex,
this.currentAction.index
);
this.activeName = clickedField.type;
this.addOptionPropOption = clickedField.options ? clickedField.options : [];
this.showOptions = true;
}
private handleClickFieldType() {
if (this.flag === FLAG_UPDATE) {
this.activeName = this.wordType; this.activeName = this.wordType;
this.addOptionPropOption = this.options; this.addOptionPropOption = this.options;
}else{ } else {
this.activeName = this.wordType; this.activeName = this.wordType;
this.addOptionPropOption = []; this.addOptionPropOption = [];
} }
this.showOptions = true; this.showOptions = true;
} }
private callbackFromMoreAction(action: any){ private callbackFromMoreAction(action: any) {
action(); action();
} }
private confirmWordType({ type = DataType.Input, options }: any) { private confirmWordType({ type = DataType.Input, options }: any) {
this.wordType = type; // 若是由直接修改表现形式而弹出add-options组件,确认完表现形式后,是直接修改当前项的值。
this.options = options; if (this.isModifyForm) {
const currentItem = this.getFocusedItem(
this.currentAction.parentIndex,
this.currentAction.index
);
currentItem.type = type;
currentItem.options = options;
} else {
// 如果不是修改表现形式,则是由对话框中点击字段类型而弹出add-options组件,若确认完表现形式,则是修改对话框中字段类型的值。
this.wordType = type;
this.options = options;
}
this.showOptions = false; this.showOptions = false;
} }
get levelObj(): any { get levelObj(): any {
if (this.wordType === DataType.Unit) { if (this.wordType === DataType.Unit) {
return { return {
title: '添加标题', title: this.flag === FLAG_UPDATE ? '更新标题' : '添加标题',
placeholder: '一级标题名称', placeholder: '一级标题名称',
toast: '标题至少2个汉字', toast: '标题至少2个汉字',
}; };
} }
return { return {
title: '添加字段', title: this.flag === FLAG_UPDATE ? '更新字段' : '添加字段',
placeholder: '字段名称', placeholder: '字段名称',
toast: '字段至少2个汉字', toast: '字段至少2个汉字',
}; };
} }
private preAddWord({ wordType, word }: any, flag: string = '') { private preAddWord({ wordType, word }: any, flag: string = '') {
this.show = true; this.show = true;
this.wordType = wordType; this.wordType = wordType;
this.currentWords = word ? word.data : this.words; this.currentWords = word ? word.data : this.words;
if (flag === 'update') { if (flag === FLAG_UPDATE) {
const { index, parentIndex } = this.currentAction; const { index, parentIndex } = this.currentAction;
const currentWord = const currentWord =
parentIndex === -1 parentIndex === -1
...@@ -332,11 +398,11 @@ export default class Add extends Vue { ...@@ -332,11 +398,11 @@ export default class Add extends Vue {
tempData = { ...tempData, options: this.options }; tempData = { ...tempData, options: this.options };
} }
let { index } = this.currentAction; let { index } = this.currentAction;
if (this.flag === 'update') { if (this.flag === FLAG_UPDATE) {
this.currentWords.splice(index, 1, tempData); this.currentWords.splice(index, 1, tempData);
} else if (this.flag === 'before') { } else if (this.flag === FLAG_BEFORE) {
this.currentWords.splice(index, 0, tempData); this.currentWords.splice(index, 0, tempData);
} else if (this.flag === 'after') { } else if (this.flag === FLAG_AFTER) {
this.currentWords.splice(++index, 0, tempData); this.currentWords.splice(++index, 0, tempData);
} else { } else {
this.currentWords.push(tempData); this.currentWords.push(tempData);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment