index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div class="airportInfo scroll-y">
  3. <div class="wrap">
  4. <Minheader :is-auth="true" :is-statuser="true" @addForm="addForm">
  5. <template #header>
  6. <div class="status flex-wrap">
  7. <div class="manageTitle">数据源管理</div>
  8. </div>
  9. </template></Minheader
  10. >
  11. <div class="app-containers">
  12. <DataTable
  13. :tableHeader="tableCols"
  14. :tableData="tableData"
  15. :tableBtnGroup="tableBtnGroup"
  16. :tableProperty="{ rowKey: 'ID' }"
  17. @btnClick="btnClick"
  18. />
  19. </div>
  20. <Dialog
  21. :flag="flag"
  22. :type="type"
  23. :msgTitle="msgTitle"
  24. @resetForm="resetForm"
  25. @delRest="delRest"
  26. @submitForm="submitForm"
  27. @delRemove="delRemove"
  28. >
  29. <div class="diacont">
  30. <el-form :model="tableForm">
  31. <el-row :gutter="24">
  32. <el-col>
  33. <el-form-item label="数据源名称" size="default">
  34. <el-input
  35. v-model="tableForm.dataSourceName"
  36. placeholder="请输入数据源名称"
  37. />
  38. </el-form-item>
  39. </el-col>
  40. <el-col>
  41. <el-form-item label="协议名称" size="default">
  42. <el-select
  43. style="width: 100%"
  44. v-model="tableForm.protocolName"
  45. class="input-shadow"
  46. filterable
  47. default-first-option
  48. clearable
  49. placeholder="请选择"
  50. >
  51. <el-option
  52. v-for="item in tableOptionser"
  53. :key="item.v ? item.v : item.planDepartureApt"
  54. :label="item.k ? item.k : item.planDepartureApt"
  55. :value="item.v ? item.v : item.planDepartureApt"
  56. >
  57. </el-option>
  58. </el-select>
  59. </el-form-item>
  60. </el-col>
  61. <el-col>
  62. <el-form-item label="连接参数" size="default">
  63. <el-input
  64. :autosize="{ minRows: 10, maxRows: 10 }"
  65. type="textarea"
  66. v-model="tableForm.connectConfig"
  67. placeholder="请输入连接参数"
  68. />
  69. </el-form-item>
  70. </el-col>
  71. </el-row>
  72. </el-form>
  73. </div>
  74. </Dialog>
  75. </div>
  76. </div>
  77. </template>
  78. <script setup lang="ts">
  79. import DataTable from "@/components/tableTemp/index.vue";
  80. import Minheader from "@/components/minheader/index.vue";
  81. import Dialog from "@/components/dialog/index.vue";
  82. import { Query, GeneralDataReception } from "@/api/webApi";
  83. import { ElMessage } from "element-plus";
  84. const page = ref<number>(0); //分页参数
  85. const dataContent = ref<object>({});
  86. const noMore = ref<Boolean>(false);
  87. const rowTitle = ref<String>("");
  88. const tableCols = ref([]); //表头数据
  89. const serviceId = ref<String>("");
  90. const tableObj = ref({}); //增删改数据缓存
  91. const flag = ref<Boolean>(false); //弹窗开关
  92. const type = ref<String>(""); //判断是否删除
  93. const msgTitle = ref<String>("新增数据源服务"); //弹窗标题
  94. const tableColsCopys = reactive<Object>({}); //弹窗
  95. const tableOptionser = ref<Array>([]); //弹窗下拉
  96. const tableForm = reactive({
  97. dataSourceID: "",
  98. protocolID: "",
  99. dataSourceName: "",
  100. connectConfig: "",
  101. protocolName: "",
  102. event: "",
  103. }); //弹窗内容
  104. //列表
  105. const tableData = ref([]);
  106. //表头
  107. const state = reactive({
  108. list: [
  109. { label: "源数据名称", key: "name" },
  110. { label: "连接参数", key: "china" },
  111. { label: "协议名称", key: "englin" },
  112. ],
  113. listLoading: true,
  114. });
  115. const tableBtnGroup = ref([
  116. {
  117. name: "编辑",
  118. className: "editBtn",
  119. param: 2,
  120. },
  121. {
  122. name: "删除",
  123. className: "delBtn",
  124. param: 3,
  125. },
  126. ]);
  127. //新增
  128. const addForm = () => {
  129. msgTitle.value = "新增数据源";
  130. tableForm.event = 1;
  131. flag.value = true;
  132. type.value = "";
  133. };
  134. //取消
  135. const resetForm = () => {
  136. flag.value = false;
  137. tableForm.dataSourceID = "";
  138. tableForm.protocolID = "";
  139. tableForm.dataSourceName = "";
  140. tableForm.connectConfig = "";
  141. tableForm.protocolName = "";
  142. };
  143. //编辑
  144. // const editDialog = (data) => {
  145. // msgTitle.value = "编辑航司信息维护";
  146. // flag.value = true;
  147. // type.value = "";
  148. // tableForm.name = data.name;
  149. // tableForm.china = data.china;
  150. // tableForm.englin = data.englin;
  151. // tableForm.two = data.two;
  152. // tableForm.three = data.three;
  153. // tableForm.text = data.text;
  154. // };
  155. //编辑-删除
  156. const btnClick = (row, index, param) => {
  157. if (param === 2) {
  158. msgTitle.value = "编辑数据源";
  159. flag.value = true;
  160. type.value = "";
  161. tableForm.event = 2;
  162. tableForm.dataSourceID = index.dataSourceID;
  163. tableForm.protocolID = index.protocolID;
  164. tableForm.dataSourceName = index.dataSourceName;
  165. tableForm.connectConfig = index.connectConfig;
  166. tableForm.protocolName = index.protocolName;
  167. } else if (param === 3) {
  168. msgTitle.value = "删除数据源";
  169. flag.value = true;
  170. type.value = "del";
  171. tableForm.event = 3;
  172. tableForm.dataSourceID = index.dataSourceID;
  173. tableForm.protocolID = index.protocolID;
  174. tableForm.dataSourceName = index.dataSourceName;
  175. tableForm.connectConfig = index.connectConfig;
  176. tableForm.protocolName = index.protocolName;
  177. } else if (param === 4) {
  178. }
  179. };
  180. //删除
  181. const eleDialog = () => {
  182. msgTitle.value = "删除数据源服务";
  183. flag.value = true;
  184. type.value = "del";
  185. };
  186. const delRemove = () => {
  187. tableForm.event = 3;
  188. generalDataReception(tableForm);
  189. };
  190. //删除
  191. const delRest = () => {
  192. flag.value = false;
  193. };
  194. //获取表格数据
  195. const getQuery = async () => {
  196. try {
  197. const { code, returnData } = await Query({
  198. id: DATACONTENT_ID.sourceDataTabId,
  199. needPage: ++page.value,
  200. dataContent: Object.values(dataContent.value),
  201. });
  202. if (code === "0") {
  203. if (returnData.listValues.length === 0) {
  204. page.value--;
  205. noMore.value = true;
  206. }
  207. const titleColumn = returnData.columnSet.find(
  208. (item) => item.needShow === 1
  209. );
  210. if (titleColumn) {
  211. rowTitle.value = titleColumn.columnName;
  212. }
  213. tableData.value.push(...returnData.listValues);
  214. tableCols.value = returnData.columnSet;
  215. tableCols.value.forEach((element) => {
  216. element.label = element.columnLabel;
  217. element.key = element.columnName;
  218. // if (element.columnName === "queryTemplate") {
  219. // element.width = "300px";
  220. // }
  221. });
  222. serviceId.value = returnData.submitID;
  223. } else {
  224. page.value--;
  225. }
  226. } catch (error) {
  227. page.value--;
  228. }
  229. };
  230. //确认提交
  231. const submitForm = () => {
  232. generalDataReception(tableForm);
  233. };
  234. const resetTable = () => {
  235. page.value = 0;
  236. noMore.value = false;
  237. tableData.value = [];
  238. };
  239. //新增-编辑-删除
  240. const generalDataReception = async (data) => {
  241. try {
  242. data = {
  243. ...data,
  244. };
  245. const { code } = await GeneralDataReception({
  246. serviceId: serviceId.value,
  247. dataContent: JSON.stringify(data),
  248. });
  249. if (code == 0) {
  250. ElMessage.success(`操作成功`);
  251. // this.$message.success("操作成功");
  252. resetTable();
  253. getQuery();
  254. resetForm();
  255. flag.value = false;
  256. // rmFlag.value = false;
  257. tableObj.value = {};
  258. // this.$router.go(0);
  259. } else {
  260. ElMessage.error(`操作失败`);
  261. // this.$message.error("操作失败");
  262. // this.flag = false;
  263. // this.rmFlag = false;
  264. tableObj.value = {};
  265. resetForm();
  266. }
  267. } catch (error) {
  268. flag.value = false;
  269. // rmFlag.value = false;
  270. tableObj.value = {};
  271. resetForm();
  272. }
  273. };
  274. getQuery();
  275. </script>
  276. <style lang="scss" scoped>
  277. ::v-deep .el-form-item__label {
  278. width: 100px;
  279. }
  280. .app-containers {
  281. height: calc(100vh - 180px);
  282. }
  283. </style>