Commit 1e2f7f3d authored by yyh's avatar yyh

userTemplate vuex

parent 61ab6382
import Vue from 'vue'; import Vue from 'vue';
const $api = Vue.prototype.$api;
const state = { const state = {
}; };
const getters = { const getters = {
...@@ -9,9 +8,7 @@ const mutations = { ...@@ -9,9 +8,7 @@ const mutations = {
}; };
const actions = { const actions = {
getProofList() {
$api.list();
},
}; };
const namespaced: boolean = true; const namespaced: boolean = true;
export const proof = { export const proof = {
......
import Vue from 'vue'; import Vue from 'vue';
const state = { const state = {
sysTemplateList: [] = [], sysTemplateList: [] = [],
userFolderList: [] = [],
}; };
const getters = { const getters = {
...@@ -9,15 +10,24 @@ const mutations = { ...@@ -9,15 +10,24 @@ const mutations = {
updateSysTemplateList(state: any, payload: any) { updateSysTemplateList(state: any, payload: any) {
state.sysTemplateList = payload || []; state.sysTemplateList = payload || [];
}, },
updateUserFolders( state: any, payload: any) {
state.userFolderList = payload || [];
},
}; };
const actions = { const actions = {
getSysTemplateList({ commit, state }: any) { getSysTemplateList({ commit }: any) {
if (state.sysTemplateList.length <= 0) { if (state.sysTemplateList.length <= 0) {
Vue.prototype.$api.template.systemList().then(({results = []}) => { Vue.prototype.$api.template.systemList().then(({results = []}) => {
commit('updateSysTemplateList', results || []); commit('updateSysTemplateList', results || []);
}); });
} }
}, },
async getUserFolders({ commit }: any) {
const { results = []} = await Vue.prototype.$api.template.folderList({template_type: 1});
const ids = results.map((folder: any) => folder.id);
const res = await Vue.prototype.$api.template.list({id: ids});
commit('updateUserFolders', res.results || []);
},
}; };
const namespaced: boolean = true; const namespaced: boolean = true;
export const template = { export const template = {
......
...@@ -82,7 +82,8 @@ export default class IndexSy extends Mixins(IndexMixin) { ...@@ -82,7 +82,8 @@ export default class IndexSy extends Mixins(IndexMixin) {
@State('isLogin') private isLogin!: boolean; @State('isLogin') private isLogin!: boolean;
@State('proofCount') private proofCount!: number; @State('proofCount') private proofCount!: number;
@Action('getProofCount') private getProofCount!: any; @Action('getProofCount') private getProofCount!: any;
private list: any[] = []; @Action('getUserFolders', { namespace: 'template'}) private getUserFolders!: () => void;
@State('userFolderList', { namespace: 'template'}) private list!: any[];
private currentFolder: object = {}; private currentFolder: object = {};
private show: boolean = false; private show: boolean = false;
private isShowRename: boolean = false; private isShowRename: boolean = false;
...@@ -105,12 +106,6 @@ export default class IndexSy extends Mixins(IndexMixin) { ...@@ -105,12 +106,6 @@ export default class IndexSy extends Mixins(IndexMixin) {
}; };
this.show = true; this.show = true;
} }
private async getUserFolders() {
const { results = []} = await this.$api.template.folderList({template_type: 1});
const ids = results.map((folder: any) => folder.id);
const res = await this.$api.template.list({id: ids});
this.list = res.results || [];
}
private async addFolder( { folderName }: any) { private async addFolder( { folderName }: any) {
this.showAddFolder = false ; this.showAddFolder = false ;
await this.$api.template.addFolder(folderName); await this.$api.template.addFolder(folderName);
......
...@@ -128,8 +128,10 @@ import PreviewTemplate from './PreviewTemplate.vue'; ...@@ -128,8 +128,10 @@ import PreviewTemplate from './PreviewTemplate.vue';
}) })
export default class SelectTemplate extends Mixins(IndexMixin) { export default class SelectTemplate extends Mixins(IndexMixin) {
@Inject('isSy') private isSy!: boolean; @Inject('isSy') private isSy!: boolean;
@Action('getUserFolders', { namespace: 'template'}) private getUserFolders!: () => void;
@State('userFolderList', { namespace: 'template'}) private userFolderList!: any[];
private active: number = 0; private active: number = 0;
private userFolderList: any[] = [];
private currentFolder: any = {}; private currentFolder: any = {};
private currentTemplate: any = {}; private currentTemplate: any = {};
private show: boolean = true; private show: boolean = true;
...@@ -142,12 +144,6 @@ export default class SelectTemplate extends Mixins(IndexMixin) { ...@@ -142,12 +144,6 @@ export default class SelectTemplate extends Mixins(IndexMixin) {
protected mounted() { protected mounted() {
this.getUserFolders(); this.getUserFolders();
} }
private async getUserFolders() {
const { results } = await this.$api.template.folderList({template_type: 1});
const ids = (results || []).map((folder: any) => folder.id);
const res = await this.$api.template.list({id: ids});
this.userFolderList = res.results || [];
}
private selectFolder(folder: any) { private selectFolder(folder: any) {
this.currentFolder = folder; this.currentFolder = folder;
this.showDetailb = false; this.showDetailb = false;
......
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