dataList.vue 6.6 KB

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