Commit 1e2f7f3d authored by yyh's avatar yyh

userTemplate vuex

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