index.vue 6.3 KB

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