index.vue 7.6 KB

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