dataList.vue 7.2 KB

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