index.vue 6.9 KB

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