index.vue 8.6 KB

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