index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <el-row>
  3. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  4. <el-col :span="24" class="one">
  5. <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch">
  6. <template #is_use>
  7. <el-option v-for="i in statusList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  8. </template>
  9. </cSearch>
  10. </el-col>
  11. <el-col :span="24" class="two">
  12. <cButton @toAdd="toAdd"> </cButton>
  13. </el-col>
  14. <el-col :span="24" class="thr">
  15. <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @edit="toEdit" @del="toDel" @changeUse="toChangeUse"> </cTable>
  16. </el-col>
  17. </el-col>
  18. </el-row>
  19. <cDialog :dialog="dialog" @toClose="toClose">
  20. <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
  21. <cForm :span="24" :fields="formFields" :form="form" :rules="{}" @save="toSave" label-width="auto">
  22. <template #file>
  23. <cUpload model="file" :list="form.file" :limit="1" url="/files/notarization/module/upload" listType="picture-card" @change="onUpload"></cUpload>
  24. </template>
  25. </cForm>
  26. </el-col>
  27. </cDialog>
  28. </template>
  29. <script setup lang="ts">
  30. import { ref, Ref, onMounted, inject } from 'vue';
  31. // NeedChange
  32. import { ModuleStore } from '@/stores/system/module';
  33. import { DictDataStore } from '@/stores/system/dictData';
  34. import type { IQueryResult } from '@/util/types.util';
  35. import { cloneDeep, get } from 'lodash';
  36. import baseStore from '@/stores/counter';
  37. const user = ref(baseStore.state.user);
  38. onMounted(async () => {
  39. loading.value = true;
  40. await searchOther();
  41. await search({ skip, limit });
  42. loading.value = false;
  43. });
  44. // 路由
  45. const loading: Ref<any> = ref(false);
  46. // NeedChange
  47. const store = ModuleStore();
  48. const dictDataStore = DictDataStore();
  49. const $checkRes = inject('$checkRes') as Function;
  50. // #region 字典
  51. // NeedChange
  52. const statusList: Ref<any> = ref([]);
  53. const searchOther = async () => {
  54. let res: IQueryResult;
  55. // 是否使用
  56. res = await dictDataStore.query({ code: 'isUse', is_use: '0' });
  57. if ($checkRes(res)) statusList.value = res.data;
  58. };
  59. // #endregion
  60. // #region 查询相关
  61. let list: Ref<any> = ref([]);
  62. let total: Ref<number> = ref(0);
  63. let skip = 0;
  64. let limit = inject('$limit') as number;
  65. let searchForm: Ref<any> = ref({});
  66. const search = async (e: { skip: number; limit: number }) => {
  67. const info = { skip: e.skip, limit: e.limit, ...searchForm.value };
  68. const res: IQueryResult = await store.query(info);
  69. if (res.errcode == '0') {
  70. list.value = res.data;
  71. total.value = res.total;
  72. }
  73. };
  74. const toSearch = (query) => {
  75. searchForm.value = query;
  76. search({ skip, limit });
  77. };
  78. const toChangeUse = async (data) => {
  79. let status = '0';
  80. switch (data.is_use) {
  81. case '0':
  82. status = '1';
  83. break;
  84. case '1':
  85. status = '0';
  86. break;
  87. default:
  88. break;
  89. }
  90. const udata = { _id: data._id, is_use: status };
  91. const res = await store.update(udata);
  92. if ($checkRes(res, true)) {
  93. search({ skip: 0, limit });
  94. }
  95. };
  96. // #endregion
  97. // #region 表格及操作
  98. // NeedChange
  99. let fields: Ref<any[]> = ref([
  100. { label: '标题', model: 'title', isSearch: true },
  101. { label: '路由', model: 'route' },
  102. { label: '排序', model: 'sort' },
  103. { label: '简介', model: 'brief' },
  104. { label: '是否使用', model: 'is_use', format: (i) => getDict(i, 'is_use'), isSearch: true, type: 'select' }
  105. ]);
  106. // 操作
  107. let opera: Ref<any[]> = ref([
  108. { label: '修改', method: 'edit' },
  109. { label: '禁用', method: 'changeUse', type: 'warning', confirm: true, display: (i) => i.is_use === '0' },
  110. { label: '使用', method: 'changeUse', type: 'success', confirm: true, display: (i) => i.is_use === '1' },
  111. { label: '删除', method: 'del', confirm: true, type: 'danger' }
  112. ]);
  113. const getDict = (data, model) => {
  114. let list;
  115. switch (model) {
  116. case 'is_use':
  117. list = statusList.value;
  118. break;
  119. default:
  120. break;
  121. }
  122. if (!list) return;
  123. const res = list.find((f) => f.value == data);
  124. return get(res, 'label');
  125. };
  126. const toAdd = () => {
  127. // 所属人是自己,需要把自己的id放进去
  128. form.value = { ...cloneDeep(defaultForm) };
  129. dialog.value.show = true;
  130. };
  131. const toEdit = async (data) => {
  132. form.value = { ...data };
  133. dialog.value.show = true;
  134. };
  135. // #endregion
  136. // #region 常规接口
  137. const toSave = async () => {
  138. const data = cloneDeep(form.value);
  139. let res: IQueryResult;
  140. if (get(data, '_id')) res = await store.update(data);
  141. else res = await store.create(data);
  142. if ($checkRes(res, true)) {
  143. search({ skip: 0, limit });
  144. toClose();
  145. }
  146. };
  147. const toDel = async (data) => {
  148. const res = await store.del(data._id);
  149. if ($checkRes(res, true)) {
  150. search({ skip: 0, limit });
  151. }
  152. };
  153. // #endregion
  154. // #region 表单及操作
  155. // NeedChange
  156. const defaultForm = { is_use: '0', file: [] };
  157. const formFields: Ref<any> = ref([
  158. { label: '图片', model: 'file', custom: true },
  159. { label: '标题', model: 'title' },
  160. { label: '路由', model: 'route' },
  161. { label: '排序', model: 'sort', type: 'number' },
  162. { label: '简介', model: 'brief', type: 'textarea' }
  163. ]);
  164. const dialog: Ref<any> = ref({ title: '数据信息', show: false, type: '1' });
  165. const form: Ref<any> = ref({ file: [] });
  166. // 关闭弹框
  167. const toClose = () => {
  168. form.value = {};
  169. dialog.value.show = false;
  170. };
  171. const onUpload = (e: { model: string; value: Array<[]> }) => {
  172. console.log(e);
  173. const { model, value } = e;
  174. form.value[model] = value;
  175. };
  176. // #endregion
  177. </script>
  178. <style scoped lang="scss">
  179. .dialog_one {
  180. .button {
  181. margin: 0 0 5px 0;
  182. }
  183. }
  184. </style>