index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. <el-button size="small" text type="primary" @click="copy(scope.row)" >复制</el-button>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <pagination
  83. v-show="tableData.total > 0"
  84. :total="tableData.total"
  85. v-model:page="tableData.param.pageNum"
  86. v-model:limit="tableData.param.pageSize"
  87. @pagination="typeList"
  88. />
  89. </el-card>
  90. <EditDic ref="editDicRef" @typeList="typeList" />
  91. <Detail ref="detailRef" />
  92. </div>
  93. </template>
  94. <script lang="ts">
  95. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  96. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  97. import EditDic from './component/edit.vue';
  98. import Detail from './component/detail.vue';
  99. import api from '/@/api/datahub';
  100. // 定义接口来定义对象的类型
  101. interface TableDataRow {
  102. id: number;
  103. name: string;
  104. key: string;
  105. createBy: string;
  106. }
  107. interface TableDataState {
  108. ids: number[];
  109. tableData: {
  110. data: Array<TableDataRow>;
  111. total: number;
  112. loading: boolean;
  113. param: {
  114. pageNum: number;
  115. pageSize: number;
  116. name: string;
  117. key: string;
  118. };
  119. };
  120. }
  121. export default defineComponent({
  122. name: 'sourcelist',
  123. components: { EditDic,Detail },
  124. setup() {
  125. const addDicRef = ref();
  126. const editDicRef = ref();
  127. const detailRef=ref();
  128. const queryRef = ref();
  129. const state = reactive<TableDataState>({
  130. tableData: {
  131. data: [],
  132. total: 0,
  133. loading: false,
  134. param: {
  135. pageNum: 1,
  136. pageSize: 10,
  137. name: '',
  138. key: '',
  139. },
  140. },
  141. });
  142. // 初始化表格数据
  143. const initTableData = () => {
  144. typeList();
  145. };
  146. const typeList = () => {
  147. state.tableData.loading = true;
  148. api.template.getList(state.tableData.param).then((res: any) => {
  149. state.tableData.data = res.list;
  150. state.tableData.total = res.Total;
  151. }).finally(() => (state.tableData.loading = false));
  152. };
  153. // 打开新增菜单弹窗
  154. const onOpenAdd = (row?: TableDataRow) => {
  155. editDicRef.value.openDialog(row?.id);
  156. };
  157. // 打开修改模型弹窗
  158. const onOpenEdit = (row: TableDataRow) => {
  159. editDicRef.value.openDialog(row);
  160. };
  161. //打开数据记录
  162. const onOpenRecord=(row: TableDataRow)=>{
  163. detailRef.value.openDialog(row);
  164. };
  165. const onRowDel = (row: TableDataRow) => {
  166. let msg = '你确定要删除所选数据?';
  167. let ids: number[] = [];
  168. if (row) {
  169. msg = `此操作将永久删除模型:“${row.name}”,是否继续?`;
  170. ids = [row.id];
  171. } else {
  172. ids = state.ids;
  173. }
  174. if (ids.length === 0) {
  175. ElMessage.error('请选择要删除的数据。');
  176. return;
  177. }
  178. ElMessageBox.confirm(msg, '提示', {
  179. confirmButtonText: '确认',
  180. cancelButtonText: '取消',
  181. type: 'warning',
  182. })
  183. .then(() => {
  184. api.template.delete(ids).then(() => {
  185. ElMessage.success('删除成功');
  186. typeList();
  187. });
  188. })
  189. .catch(() => {});
  190. };
  191. //复制数据
  192. const copy=(row:TableDataRow)=>{
  193. ElMessageBox.confirm("确定要复制该数据吗?", '提示', {
  194. confirmButtonText: '确认',
  195. cancelButtonText: '取消',
  196. type: 'warning',
  197. })
  198. .then(() => {
  199. api.template.copy({id:row.id}).then(() => {
  200. ElMessage.success('复制成功');
  201. typeList();
  202. });
  203. })
  204. .catch(() => {});
  205. }
  206. // 页面加载时
  207. onMounted(() => {
  208. initTableData();
  209. });
  210. /** 重置按钮操作 */
  211. const resetQuery = (formEl: FormInstance | undefined) => {
  212. if (!formEl) return;
  213. formEl.resetFields();
  214. typeList();
  215. };
  216. // 多选框选中数据
  217. const handleSelectionChange = (selection: TableDataRow[]) => {
  218. state.ids = selection.map((item) => item.id);
  219. };
  220. return {
  221. addDicRef,
  222. editDicRef,
  223. detailRef,
  224. queryRef,
  225. onOpenRecord,
  226. onOpenAdd,
  227. onOpenEdit,
  228. onRowDel,
  229. copy,
  230. typeList,
  231. resetQuery,
  232. handleSelectionChange,
  233. ...toRefs(state),
  234. };
  235. },
  236. });
  237. </script>