index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch">
  7. <template #type>
  8. <el-option v-for="i in typeList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  9. </template>
  10. </cSearch>
  11. </el-col>
  12. <el-col :span="24" class="two">
  13. <cButton @toAdd="toAdd()"> </cButton>
  14. </el-col>
  15. <el-col :span="24" class="thr">
  16. <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @exam="toExam" @edit="toEdit" @del="toDel">
  17. <template #is_use="{ row }">
  18. <el-switch
  19. v-model="row.is_use"
  20. inline-prompt
  21. active-text="是"
  22. inactive-text="否"
  23. active-value="0"
  24. inactive-value="1"
  25. @click="handleChange(row)"
  26. ></el-switch>
  27. </template>
  28. </cTable>
  29. </el-col>
  30. </el-col>
  31. </el-row>
  32. <cDialog :dialog="dialog" @toClose="toClose">
  33. <template v-slot:info>
  34. <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
  35. <cForm :span="24" :fields="formFields" :form="form" :rules="{}" @save="toSave" label-width="auto">
  36. <template #status>
  37. <el-option v-for="i in statusList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  38. </template>
  39. </cForm>
  40. </el-col>
  41. </template>
  42. </cDialog>
  43. </div>
  44. </template>
  45. <script setup lang="ts">
  46. // 基础
  47. import store from '@/stores/counter';
  48. import type { Ref } from 'vue';
  49. import { ref, onMounted, getCurrentInstance } from 'vue';
  50. import { ElMessage, ElMessageBox } from 'element-plus';
  51. import { useRouter } from 'vue-router';
  52. // 接口
  53. import { ArticleStore } from '@/stores/content/article';
  54. import { DictDataStore } from '@/stores/basic/dictData'; // 字典表
  55. import type { IQueryResult } from '@/util/types.util';
  56. const articleAxios = ArticleStore();
  57. const dictAxios = DictDataStore();
  58. const { proxy } = getCurrentInstance() as any;
  59. let user: Ref<any> = ref(store.state.user);
  60. // 路由
  61. const router = useRouter();
  62. // 加载中
  63. const loading: Ref<any> = ref(false);
  64. let list: Ref<any> = ref([]);
  65. let total: Ref<number> = ref(0);
  66. let skip = 0;
  67. let limit: number = proxy.$limit;
  68. let fields: Ref<any[]> = ref([
  69. { label: '发布人', model: 'contact_name', isSearch: true },
  70. { label: '标题', model: 'title', isSearch: true },
  71. { label: '类型', model: 'type', type: 'select', isSearch: true, format: (i: any) => getDict(i) },
  72. { label: '创建时间', model: 'create_time' },
  73. { label: '排序', model: 'sort', type: 'number' },
  74. { label: '是否启用', model: 'is_use', custom: true }
  75. ]);
  76. // 操作
  77. let opera: Ref<any[]> = ref([
  78. { label: '审核', method: 'exam', type: 'warning', display: (i: any) => i.status == '0' && user.value.type == '0' },
  79. { label: '修改', method: 'edit' },
  80. { label: '删除', method: 'del', confirm: true, type: 'danger' }
  81. ]);
  82. // 查询数据
  83. let searchForm: Ref<any> = ref({});
  84. // 字典表
  85. let is_useList: Ref<any> = ref([]);
  86. let statusList: Ref<any> = ref([]);
  87. let typeList: Ref<any> = ref([]);
  88. // 弹框
  89. const dialog: Ref<any> = ref({ title: '信息管理', show: false, type: '1' });
  90. const form: Ref<any> = ref({});
  91. const formFields: Ref<any> = ref([{ label: '状态', model: 'status', type: 'select' }]);
  92. // 请求
  93. onMounted(async () => {
  94. loading.value = true;
  95. await searchOther();
  96. await search({ skip, limit });
  97. loading.value = false;
  98. });
  99. const search = async (e: { skip: number; limit: number }) => {
  100. const info = { skip: e.skip, limit: e.limit, ...searchForm.value };
  101. const res: any = await articleAxios.query(info);
  102. if (res.errcode == '0') {
  103. list.value = res.data;
  104. total.value = res.total;
  105. }
  106. };
  107. const toSearch = (query: any) => {
  108. searchForm.value = query;
  109. search({ skip, limit });
  110. };
  111. const getDict = (value: any) => {
  112. if (value) {
  113. let data = typeList.value.find((i: any) => i.value == value);
  114. if (data) return data.label;
  115. else return '暂无';
  116. }
  117. };
  118. // 审核
  119. const toExam = async (data: any) => {
  120. let res: IQueryResult = await articleAxios.fetch(data._id);
  121. if (res.errcode == '0') {
  122. form.value = res.data;
  123. dialog.value = { title: '审核管理', show: true, type: '1' };
  124. }
  125. };
  126. // 提交保存
  127. const toSave = async (data: any) => {
  128. let res: IQueryResult;
  129. if (data._id) res = await articleAxios.update(data);
  130. else res = await articleAxios.create(data);
  131. if (res.errcode == 0) {
  132. ElMessage({ type: `success`, message: `维护信息成功` });
  133. toClose();
  134. }
  135. };
  136. // 新增
  137. const toAdd = () => {
  138. router.push({ path: '/content/article/detail' });
  139. };
  140. // 修改
  141. const toEdit = async (data: any) => {
  142. router.push({ path: '/content/article/detail', query: { id: data._id } });
  143. };
  144. // 删除
  145. const toDel = async (data: any) => {
  146. let res: IQueryResult = await articleAxios.del(data._id);
  147. if (res.errcode == 0) {
  148. ElMessage({ type: `success`, message: `刪除信息成功` });
  149. search({ skip, limit });
  150. }
  151. };
  152. // 关闭弹框
  153. const toClose = () => {
  154. form.value = { file: [] };
  155. dialog.value = { show: false };
  156. search({ skip, limit });
  157. };
  158. // 查询其他信息
  159. const searchOther = async () => {
  160. let res: IQueryResult;
  161. res = await dictAxios.query({ type: 'is_use', is_use: '0' });
  162. if (res.errcode == 0) is_useList.value = res.data;
  163. // 状态
  164. res = await dictAxios.query({ type: 'exam_status', is_use: '0' });
  165. if (res.errcode == '0') statusList.value = res.data;
  166. // 类型
  167. res = await dictAxios.query({ type: 'home_tabs', is_use: '0' });
  168. if (res.errcode == '0') typeList.value = res.data;
  169. };
  170. // 修改是否启用
  171. const handleChange = (row: any) => {
  172. const text = row.is_use === '0' ? '启用' : '停用';
  173. ElMessageBox.confirm('确认要"' + text + '""' + row.title + '"吗?', '提示', {
  174. confirmButtonText: '确定',
  175. cancelButtonText: '取消',
  176. type: 'warning'
  177. })
  178. .then(async () => {
  179. let res: IQueryResult;
  180. if (row._id) res = await articleAxios.update(row);
  181. if (res.errcode == 0) {
  182. ElMessage({ type: `success`, message: `修改成功` });
  183. }
  184. })
  185. .catch(() => {
  186. row.is_use = row.is_use === '0' ? '1' : '0';
  187. });
  188. };
  189. </script>
  190. <style scoped lang="scss">
  191. .main {
  192. .two {
  193. margin: 0 0 10px 0;
  194. }
  195. }
  196. </style>