dataList.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div class="page">
  3. <el-card shadow="never">
  4. <el-form :model="tableData.param" ref="queryRef" inline>
  5. <el-form-item label="字典类型" prop="dictType">
  6. <el-input v-model="tableData.param.dictType" placeholder="请输入字典类型" clearable @keyup.enter.native="dataList" />
  7. </el-form-item>
  8. <el-form-item label="字典标签" prop="dictLabel">
  9. <el-input v-model="tableData.param.dictLabel" placeholder="请输入字典标签" style="width: 150px" clearable @keyup.enter.native="dataList" />
  10. </el-form-item>
  11. <el-form-item label="状态" prop="status">
  12. <el-select v-model="tableData.param.status" placeholder="字典状态" style="width: 120px">
  13. <el-option label="全部" :value="-1" />
  14. <el-option label="启用" :value="1" />
  15. <el-option label="禁用" :value="0" />
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button type="primary" class="ml10" @click="dataList">
  20. <el-icon>
  21. <ele-Search />
  22. </el-icon>
  23. 查询
  24. </el-button>
  25. <el-button type="primary" class="ml10" @click="onOpenAddDic" v-auth="'add'">
  26. <el-icon>
  27. <ele-FolderAdd />
  28. </el-icon>
  29. 新增字典
  30. </el-button>
  31. <el-button type="danger" class="ml10" @click="onRowDel()" v-auth="'del'">
  32. <el-icon>
  33. <ele-Delete />
  34. </el-icon>
  35. 删除字典
  36. </el-button>
  37. </el-form-item>
  38. </el-form>
  39. <el-table :data="tableData.data" style="width: 100%" @selection-change="handleSelectionChange">
  40. <el-table-column type="selection" width="55" align="center" />
  41. <el-table-column label="字典编码" v-col="'dictCode'" width="90" align="center" prop="dictCode" />
  42. <el-table-column label="字典标签" v-col="'dictLabel'" align="center" prop="dictLabel" />
  43. <el-table-column label="字典键值" v-col="'dictValue'" align="center" prop="dictValue" />
  44. <el-table-column label="字典排序" v-col="'dictSort'" width="100" align="center" prop="dictSort" />
  45. <el-table-column label="备注" v-col="'remark'" align="center" prop="remark" show-overflow-tooltip />
  46. <!-- <el-table-column label="创建时间" align="center" prop="createdAt" width="180" /> -->
  47. <el-table-column prop="status" label="字典状态" v-col="'status'" width="120" align="center">
  48. <template #default="scope">
  49. <el-tag type="success" size="small" v-if="scope.row.status">启用</el-tag>
  50. <el-tag type="info" size="small" v-else>禁用</el-tag>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="操作" width="100" align="center" v-col="'handle'">
  54. <template #default="scope">
  55. <el-button size="small" text type="warning" @click="onOpenEditDic(scope.row)" v-auth="'edit'">修改</el-button>
  56. <el-button size="small" text type="danger" @click="onRowDel(scope.row)" v-auth="'del'">删除</el-button>
  57. </template>
  58. </el-table-column>
  59. </el-table>
  60. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="dataList" />
  61. </el-card>
  62. <EditDic ref="editDicRef" @dataList="dataList" :dict-type="tableData.param.dictType" />
  63. </div>
  64. </template>
  65. <script lang="ts">
  66. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  67. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  68. import EditDic from './component/editDicData.vue';
  69. import api from '/@/api/system';
  70. import { useRoute } from 'vue-router';
  71. // 定义接口来定义对象的类型
  72. interface TableDataRow {
  73. dictCode: number;
  74. dictSort: number;
  75. dictLabel: string;
  76. dictValue: string;
  77. dictType: string;
  78. status: number;
  79. remark: string;
  80. createdAt: string;
  81. }
  82. interface TableDataState {
  83. ids: number[];
  84. tableData: {
  85. data: Array<TableDataRow>;
  86. total: number;
  87. loading: boolean;
  88. param: {
  89. pageNum: number;
  90. pageSize: number;
  91. dictType: string;
  92. dictLabel: string;
  93. status: number;
  94. };
  95. };
  96. }
  97. export default defineComponent({
  98. name: 'apiV1SystemDictDataList',
  99. components: { EditDic },
  100. setup() {
  101. const route = useRoute();
  102. const addDicRef = ref();
  103. const editDicRef = ref();
  104. const queryRef = ref();
  105. const state = reactive<TableDataState>({
  106. ids: [],
  107. tableData: {
  108. data: [],
  109. total: 0,
  110. loading: false,
  111. param: {
  112. pageNum: 1,
  113. pageSize: 20,
  114. dictLabel: '',
  115. dictType: '',
  116. status: -1,
  117. },
  118. },
  119. });
  120. // 初始化表格数据
  121. const initTableData = () => {
  122. dataList();
  123. };
  124. const dataList = () => {
  125. api.dict.getDataList(state.tableData.param).then((res: any) => {
  126. state.tableData.data = res.list;
  127. state.tableData.total = res.total;
  128. });
  129. };
  130. // 打开新增字典弹窗
  131. const onOpenAddDic = () => {
  132. editDicRef.value.openDialog();
  133. };
  134. // 打开修改字典弹窗
  135. const onOpenEditDic = (row: TableDataRow) => {
  136. editDicRef.value.openDialog(row);
  137. };
  138. // 删除字典
  139. const onRowDel = (row?: TableDataRow) => {
  140. let msg = '你确定要删除所选数据?';
  141. let ids: number[] = [];
  142. if (row) {
  143. msg = `此操作将永久删除用户:“${row.dictLabel}”,是否继续?`;
  144. ids = [row.dictCode];
  145. } else {
  146. ids = state.ids;
  147. }
  148. if (ids.length === 0) {
  149. ElMessage.error('请选择要删除的数据。');
  150. return;
  151. }
  152. ElMessageBox.confirm(msg, '提示', {
  153. confirmButtonText: '确认',
  154. cancelButtonText: '取消',
  155. type: 'warning',
  156. })
  157. .then(() => {
  158. api.dict.deleteData(ids).then(() => {
  159. ElMessage.success('删除成功');
  160. dataList();
  161. });
  162. })
  163. .catch(() => { });
  164. };
  165. // 页面加载时
  166. onMounted(() => {
  167. const dictType = route.params && route.params.dictType;
  168. state.tableData.param.dictType = <string>dictType;
  169. initTableData();
  170. });
  171. /** 重置按钮操作 */
  172. const resetQuery = (formEl: FormInstance | undefined) => {
  173. if (!formEl) return;
  174. formEl.resetFields();
  175. dataList();
  176. };
  177. // 多选框选中数据
  178. const handleSelectionChange = (selection: TableDataRow[]) => {
  179. state.ids = selection.map((item) => item.dictCode);
  180. };
  181. return {
  182. addDicRef,
  183. editDicRef,
  184. queryRef,
  185. onOpenAddDic,
  186. onOpenEditDic,
  187. onRowDel,
  188. dataList,
  189. resetQuery,
  190. handleSelectionChange,
  191. ...toRefs(state),
  192. };
  193. },
  194. });
  195. </script>