index.vue 8.8 KB

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