2 Komitmen 75691f8baa ... df10bbaf44

Pembuat SHA1 Pesan Tanggal
  youyawu df10bbaf44 dict 4 tahun lalu
  youyawu 1914c9a35c dict 4 tahun lalu

+ 20 - 10
src/api/dict.ts

@@ -1,14 +1,24 @@
 import { post } from "@/utils/request";
-import dict from "@/store/modules/dict";
-
-export const getDict = (dictType: string) => {
-  post("/common/dict", { dictType }).then(([err, data]) => {
+const types = ["company_type", "examine_status"];
+export const getDict = async () => {
+  const arr = await Promise.all(
+    types.map(dictType =>
+      post<{ list: IAny[] }>("/common/dict", {
+        dictType
+      })
+    )
+  );
+  const data: IDicts = {};
+  types.map((k, i) => {
+    const [err, { list = [] }] = arr[i];
     if (err) return;
-    const v = data.list.map((x: any) => ({
-      key: x.dictLabel,
-      value: x.dictValue
-    })) as IDict[];
-    dict.add({ k: dictType, v });
+    data[k] = list.map(
+      (x: any) =>
+        ({
+          key: x.dictLabel,
+          value: x.dictValue
+        } as IDict)
+    );
   });
-  return [{ key: "请选择", value: "" }] as IDict[];
+  return data;
 };

+ 7 - 2
src/layout/components/LangSelect.vue

@@ -17,10 +17,11 @@ import { Component, Vue, Watch } from "vue-property-decorator";
 import { setLocale } from "@/lang";
 import { setPageTitle } from "@/utils";
 import menu from "@/store/modules/menu";
+import dict from "@/store/modules/dict";
 @Component
 export default class extends Vue {
   created() {
-    menu.getList();
+    this.getList();
   }
 
   get language() {
@@ -35,13 +36,17 @@ export default class extends Vue {
   private handleSetLanguage(lang: string) {
     setLocale(lang);
     setPageTitle(this.$route.meta.title);
-    menu.getList();
+    this.getList();
 
     this.$message({
       message: `${this.$i18n.t("SLS")}`,
       type: "success"
     });
   }
+  private getList() {
+    menu.getList();
+    dict.getList();
+  }
 }
 </script>
 <style lang="scss" scoped>

+ 23 - 14
src/store/modules/dict.ts

@@ -5,24 +5,33 @@ import {
   Mutation,
   Action
 } from "vuex-module-decorators";
-interface IAdd {
-  k: string;
-  v: IDict[];
-}
 import store from "../index";
 import { getDict } from "@/api/dict";
-@Module({ dynamic: true, store, name: "dict" })
+import i18n from "@/lang";
+import vue from "vue";
+@Module({ dynamic: true, store, name: "dict", namespaced: true })
 class Dict extends VuexModule {
-  public companyType = getDict("company_type");
-  public examineStatus = getDict("examine_status");
+  private data: {
+    [index: string]: IDicts;
+  } = {};
+
+  @Action
+  public async getList() {
+    const list = await getDict();
+    this.setList(list);
+  }
   @Mutation
-  public add({ k, v }: IAdd) {
-    switch (k) {
-      case "company_type":
-        return (this.companyType = v);
-      case "examine_status":
-        return (this.examineStatus = v);
-    }
+  private setList(list: IDicts) {
+    vue.set(this.data, i18n.locale, list);
+  }
+  get list() {
+    return this.data[i18n.locale] || {};
+  }
+  get companyType() {
+    return this.list.company_type || [];
+  }
+  get examineStatus() {
+    return this.list.examine_status || [];
   }
 }
 export default getModule(Dict);

+ 1 - 1
src/store/modules/menu.ts

@@ -9,7 +9,7 @@ import store from "../index";
 import { getMenu } from "@/api/menu";
 import i18n from "@/lang";
 import vue from "vue";
-@Module({ dynamic: true, store, name: "menu" })
+@Module({ dynamic: true, store, name: "menu", namespaced: true })
 class Menu extends VuexModule {
   private data: {
     [index: string]: IMenu[];

+ 1 - 1
src/store/modules/user.ts

@@ -9,7 +9,7 @@ import { auth } from "@/utils/cookies";
 import { getUserInfo, getToken } from "@/api/user";
 import store from "../index";
 
-@Module({ dynamic: true, store, name: "user" })
+@Module({ dynamic: true, store, name: "user", namespaced: true })
 class User extends VuexModule {
   public Token = auth.getToken() || "";
   public UserInfo: IUser | null = null;

+ 4 - 0
src/types/global.d.ts

@@ -53,3 +53,7 @@ interface IDict {
   key: string;
   value: string;
 }
+
+interface IDicts {
+  [index: string]: IDict[];
+}

+ 6 - 2
src/views/shops/enter/index.vue

@@ -98,13 +98,13 @@
   </div>
 </template>
 <script lang="ts">
-import { Component, Vue } from "vue-property-decorator";
+import { Component, Vue, Watch } from "vue-property-decorator";
 import dict from "@/store/modules/dict";
 import i18n from "@/lang";
 @Component({ name: "shopEnter" })
 export default class extends Vue {
   private companyName = "";
-  private status = i18n.t(`pleaseChoose`);
+  private status: string | number = "";
   private params = {};
   private items: any[] | null = [];
   get statusList() {
@@ -121,6 +121,10 @@ export default class extends Vue {
   setItems(items: any[]) {
     this.items = items.length ? items : null;
   }
+  @Watch("$i18n.locale", { immediate: true })
+  change() {
+    this.status = `${this.$i18n.t(`pleaseChoose`)}`;
+  }
 }
 </script>
 <style scoped lang="scss">