index.vue 8.0 KB

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