index.vue 9.3 KB

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