Commit 323ec9b7 authored by chenqikuai's avatar chenqikuai

feat: 新增系统模板的编辑功能

系统模板可以编辑,编辑后保存到指定的文件夹中(默认文件夹是‘未分类文件夹’)
parent 60cc7d5c
...@@ -95,12 +95,15 @@ export default class Template extends Vue { ...@@ -95,12 +95,15 @@ export default class Template extends Vue {
this.focusedTemplateId = templateId; this.focusedTemplateId = templateId;
} }
private editTemplate(folder: any) { private editTemplate(folder: any , isSystemCategory: boolean) {
const { id } = folder; const { id, folderId } = folder;
this.$router.push({ this.$router.push({
name: 'EditTemplate', name: 'EditTemplate',
query: { query: {
id, id,
folderId,
sys: JSON.stringify(isSystemCategory),
}, },
}); });
} }
......
...@@ -148,7 +148,11 @@ const routes: RouteConfig[] = [ ...@@ -148,7 +148,11 @@ const routes: RouteConfig[] = [
path: '/editTemplate', path: '/editTemplate',
name: 'EditTemplate', name: 'EditTemplate',
component: () => import(/* webpackChunkName: "edit-template" */ '@/views/template/EditTemplate.vue'), component: () => import(/* webpackChunkName: "edit-template" */ '@/views/template/EditTemplate.vue'),
props: ({query}) => ({ id: Number.parseInt(query.id as string, 10) }), props: ({query}) => ({
id: Number.parseInt(query.id as string, 10),
folderId: query.folderId !== undefined ? Number.parseInt(query.folderId as string, 10) : undefined,
sys: query.sys !== undefined ? JSON.parse(query.sys as string) : false,
}),
meta: { requiresAuth: true }, meta: { requiresAuth: true },
}, },
{ {
......
<template> <template>
<div> <div>
<base-info
ref="baseInfo"
title="编辑模板"
:showBaseInfo.sync="showBaseInfo"
:defaultFolderId="folderId"
@next="baseInfoNext"
@cancel="cancelCreateTempl"
></base-info>
<words-manager <words-manager
:data.sync="words" :data.sync="words"
@show-preview="showPreview = true" @show-preview="showPreview = true"
...@@ -30,6 +38,8 @@ import WordsManager from './components/WordsManager.vue'; ...@@ -30,6 +38,8 @@ import WordsManager from './components/WordsManager.vue';
}) })
export default class Add extends Vue { export default class Add extends Vue {
@Prop() private id!: number; @Prop() private id!: number;
@Prop({ required: false }) private folderId!: number | undefined;
@Prop() private sys!: boolean;
private showBaseInfo: boolean = true; private showBaseInfo: boolean = true;
...@@ -59,26 +69,50 @@ export default class Add extends Vue { ...@@ -59,26 +69,50 @@ export default class Add extends Vue {
const ret = await this.$api.template.get(id); const ret = await this.$api.template.get(id);
const detail = JSON.parse(ret.detail); const detail = JSON.parse(ret.detail);
this.words = detail; this.words = detail;
this.initBaseInfoCmpData(ret);
} }
private baseInfoNext(data: any) { private initBaseInfoCmpData(ret: any) {
console.log(data); const baseInfoCmp = this.$refs.baseInfo as any;
baseInfoCmp.templateName = ret.name;
baseInfoCmp.imgUrl = ret.s_image_url;
}
private baseInfoNext(data: any) {
this.baseInfo = { ...data }; this.baseInfo = { ...data };
} }
private cancelCreateTempl() { private cancelCreateTempl() {
this.$router.back(); this.$router.back();
} }
private commitTemplate() { private commitTemplate() {
if (this.words.length <= 0) { if (this.words.length <= 0) {
return Promise.reject('请添加字段'); return Promise.reject('请添加字段');
} }
/* 更新存证 */
return this.$api.template.updateCustomize({ if (this.sys) {
id: this.id, /*编辑系统模板后,需要 新增存证 */
detail: JSON.stringify(this.words), return this.$api.template.customize(
}); this.baseInfo.templateName,
this.words,
this.folderId,
{
s_image_url: this.baseInfo.imgUrl,
}
);
} else {
/* 编辑非系统模板时, 只需更新存证 */
return this.$api.template.updateCustomize({
id: this.id,
folder_id: this.folderId,
name: this.baseInfo.templateName,
detail: JSON.stringify(this.words),
s_image_url: this.baseInfo.imgUrl,
});
}
} }
private async confirm() { private async confirm() {
try { try {
/* 创建存证 */ /* 创建存证 */
...@@ -110,7 +144,6 @@ export default class Add extends Vue { ...@@ -110,7 +144,6 @@ export default class Add extends Vue {
name: 'ProofDetail', name: 'ProofDetail',
query: { templateId: res.id }, query: { templateId: res.id },
}); });
} catch (err) { } catch (err) {
this.$toast(err); this.$toast(err);
} }
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
:key="id" :key="id"
@click.native="goProofDetail(id)" @click.native="goProofDetail(id)"
@show-more-action="showMoreAction" @show-more-action="showMoreAction"
:isSystemTemplate="isSystemCategory()"
:id="id" :id="id"
:thumb="s_image_url" :thumb="s_image_url"
:title="name" :title="name"
...@@ -156,7 +155,7 @@ export default class List extends Mixins(TemplateMixin) { ...@@ -156,7 +155,7 @@ export default class List extends Mixins(TemplateMixin) {
const isSystemCategory = this.isSystemCategory(); const isSystemCategory = this.isSystemCategory();
const { rename, move, copy, del, edit } = this.ActionList; const { rename, move, copy, del, edit } = this.ActionList;
if (isSystemCategory) { if (isSystemCategory) {
return []; return [edit];
} else { } else {
return [edit, rename, move, copy, del]; return [edit, rename, move, copy, del];
} }
...@@ -164,7 +163,7 @@ export default class List extends Mixins(TemplateMixin) { ...@@ -164,7 +163,7 @@ export default class List extends Mixins(TemplateMixin) {
private async callbackAction(cb: any) { private async callbackAction(cb: any) {
// cb是什么东西? // cb是什么东西?
this.isShowRename = await cb.call(this, this.currentTem); this.isShowRename = await cb.call(this, this.currentTem, this.isSystemCategory());
this.getTemplateListToList(+this.id); this.getTemplateListToList(+this.id);
} }
...@@ -173,7 +172,10 @@ export default class List extends Mixins(TemplateMixin) { ...@@ -173,7 +172,10 @@ export default class List extends Mixins(TemplateMixin) {
} }
private showMoreAction(data: any) { private showMoreAction(data: any) {
const template = this.getTemplateById(data.id); const template = {
...this.getTemplateById(data.id),
folderId: this.id,
};
this.currentTem = template; this.currentTem = template;
this.show = true; this.show = true;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
name="shanchu5" name="shanchu5"
style="position:absolute;left:17px;" style="position:absolute;left:17px;"
></common-svg> ></common-svg>
<span>创建模板</span> <span>{{ title !== undefined ? title : '创建模板' }}</span>
</div> </div>
<van-field v-model="templateName" placeholder="填写模板名称"></van-field> <van-field v-model="templateName" placeholder="填写模板名称"></van-field>
<input <input
...@@ -41,11 +41,9 @@ ...@@ -41,11 +41,9 @@
<common-svg name="jinru"></common-svg> <common-svg name="jinru"></common-svg>
</label> </label>
<div class="btn-group"> <div class="btn-group">
<div> <div @click="handleClickFolder">
所在文件夹: <span>所在文件夹</span>:
<span class="classify" @click="handleClickFolder">{{ <span class="classify">{{ folder && folder.name }}</span>
folder && folder.name
}}</span>
</div> </div>
<div @click="next" class="slc-btn-common next">下一步</div> <div @click="next" class="slc-btn-common next">下一步</div>
</div> </div>
...@@ -109,6 +107,7 @@ const Template = namespace('template'); ...@@ -109,6 +107,7 @@ const Template = namespace('template');
export default class BaseInfo extends Vue { export default class BaseInfo extends Vue {
private EFolderListMode = EFolderListMode; private EFolderListMode = EFolderListMode;
@Prop({ required: false }) private defaultFolderId!: number | undefined; @Prop({ required: false }) private defaultFolderId!: number | undefined;
@Prop({ required: false }) private title!: string;
@PropSync('showBaseInfo', { type: Boolean, required: true }) @PropSync('showBaseInfo', { type: Boolean, required: true })
private show!: boolean; private show!: boolean;
...@@ -142,23 +141,34 @@ export default class BaseInfo extends Vue { ...@@ -142,23 +141,34 @@ export default class BaseInfo extends Vue {
if (this.defaultFolderId !== undefined) { if (this.defaultFolderId !== undefined) {
this.findFolderByIdContinually(this.defaultFolderId); this.findFolderByIdContinually(this.defaultFolderId);
this.folderId = this.defaultFolderId; this.folderId = this.defaultFolderId;
} else {
this.findFolderByIdContinually(undefined);
} }
} }
/* /*
查找指定id的folder,把folder相关数据保存到data中。 查找指定id的folder,把folder相关数据保存到data中。
*/ */
private async findFolderByIdContinually(folderId: number) { private async findFolderByIdContinually(folderId: number | undefined) {
const matchedFolderIndex = this.userFolderList.findIndex((folder: any) => { const matchedFolderIndex = this.userFolderList.findIndex((folder: any) => {
return folder.id === folderId; if (folderId !== undefined) {
return folder.id === folderId;
} else {
return folder.name === this.defaultFolderName;
}
}); });
if (matchedFolderIndex !== -1) { if (matchedFolderIndex !== -1) {
// ok 找到文件了或者请求完所有的数据后没有对应的文件 // ok 找到文件了或者请求完所有的数据后没有对应的文件
this.folder = this.userFolderList[matchedFolderIndex]; this.folder = this.userFolderList[matchedFolderIndex];
this.defaultFolderIndex = matchedFolderIndex; this.defaultFolderIndex = matchedFolderIndex;
if (folderId === undefined) {
this.$router.replace({
query: { ...this.$route.query, folderId: this.folder.id },
});
}
} else if (this.isFinished) { } else if (this.isFinished) {
this.$router.push({ name: '' }); this.$router.push({ name: '' });
throw new Error('文件夹列表中无法找到指定id的文件夹'); throw new Error('文件夹列表中无法找到指定的文件夹');
} else { } else {
// continue request // continue request
this.setPage(this.page + 1); this.setPage(this.page + 1);
......
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
</div> </div>
<TemplateListContainer <TemplateListContainer
v-else v-else
:isFolderList="isFolderList"
:templateList="templateList" :templateList="templateList"
:folderId="folderId"
class="template-list" class="template-list"
/> />
</div> </div>
......
...@@ -49,13 +49,27 @@ export default class Index extends Vue { ...@@ -49,13 +49,27 @@ export default class Index extends Vue {
@Prop() list!: any[]; @Prop() list!: any[];
@Prop() selectedId!: number | null; @Prop() selectedId!: number | null;
@Prop() loading!: boolean; @Prop() loading!: boolean;
@Prop() folderId!: number;
@Prop() isFolderList!: boolean;
handleClickEditTemplate(templateId: number) { handleClickEditTemplate(templateId: number) {
let query: any = {
id: templateId.toString(),
};
if (this.isFolderList) {
query = {
...query,
folderId: this.folderId.toString(),
};
}else{
query = {
...query,
sys: true
}
}
this.$router.push({ this.$router.push({
name: 'EditTemplate', name: 'EditTemplate',
query: { query,
id: templateId.toString(),
},
}); });
} }
get noData() { get noData() {
......
<template> <template>
<div class="template-list-container"> <div class="template-list-container">
<TemplateList <TemplateList
:isFolderList="isFolderList"
:list="templateList" :list="templateList"
:selectedId="selectedId" :selectedId="selectedId"
:folderId="folderId"
:handleSelectItem="handleClickItem" :handleSelectItem="handleClickItem"
/> />
<div class="placeholder-block" v-if="isTemplateSelected"></div> <div class="placeholder-block" v-if="isTemplateSelected"></div>
...@@ -34,6 +36,8 @@ import PreviewTemplate from '@/views/template/components/PreviewTemplate.vue'; ...@@ -34,6 +36,8 @@ import PreviewTemplate from '@/views/template/components/PreviewTemplate.vue';
}) })
export default class Index extends Vue { export default class Index extends Vue {
@Prop() templateList!: []; @Prop() templateList!: [];
@Prop() folderId!: number;
@Prop() isFolderList!: boolean;
selectedId: null | number = null; selectedId: null | number = null;
detail: any = null; detail: any = null;
......
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