accessPageNode copy.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div class="accessPageNode">
  3. <div style="height: 100%;" class="accessPageNode-items">
  4. <nodeBtn v-for="(item,index) in nodeItems" :nodeIndex="index" :nodeItem="item" :nodeTxt="item.algorithmname" :isLine="item.isLine" :isDel="item.isDel" :key="index" @handleAdd="handleAdd" @handleDel="handleDel" @handleEdit="handleEdit" />
  5. </div>
  6. <PublicPageDialog class="advancedNode" :dialog-title="dialogTitle" dialogSize="600px" :dialog-drawer="advancedDrawer" @handleClose="advancedClose" @handleSubmit="advancedTable">
  7. <div v-if="!tabFlag" class="nodeForm">
  8. <el-form :inline="true" :model="formInline" class="nodeForm-inline">
  9. <el-form-item label="分类">
  10. <el-select size="small" v-model="formInline.algorithmtype" @change="changeSelect('algorithmtype',formInline.algorithmtype)" clearable placeholder="全部分类">
  11. <el-option v-for="(item,index) in selectType" :key="index" :label="item.name" :value="item.code"></el-option>
  12. </el-select>
  13. </el-form-item>
  14. </el-form>
  15. <div v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" style="margin-top: 20px">
  16. <template v-if="selectAlgorithm.length">
  17. <el-radio-group style="width: 100%;" v-model="radio3" size="small">
  18. <el-row :gutter="20">
  19. <el-col style="margin-bottom: 20px;" v-for="(item,index) in selectAlgorithm" :key="index" :span="8">
  20. <el-radio :label="item.id" border>{{ item.name }}</el-radio>
  21. </el-col>
  22. </el-row>
  23. </el-radio-group>
  24. </template>
  25. <template v-else>
  26. <el-empty description="暂无数据"></el-empty>
  27. </template>
  28. </div>
  29. </div>
  30. <div v-else class="nodeItemForm">
  31. <el-form ref="ruleForm" :model="tableForm" label-width="100px">
  32. <el-row :gutter="20">
  33. <el-col :span="24">
  34. <el-form-item prop="algorithmname" label="算法名称">
  35. <el-input size="small" v-model="tableForm.algorithmname" placeholder="请输入" />
  36. </el-form-item>
  37. </el-col>
  38. <el-col v-if="formatData(formInline.algorithmtype) == 'java' || formatData(formInline.algorithmtype) == 'db' || formatData(formInline.algorithmtype) == 'kafka'" :span="24">
  39. <el-form-item prop="datasourceid" label="数据源">
  40. <el-select size="small" v-model="tableForm.datasourceid" @change="changeSelectSocure('datasourceid')" placeholder="请选择">
  41. <el-option v-for="(item,index) in selectSource" :key="index" :label="item.datasourcedescribe" :value="item.datasourceid"></el-option>
  42. </el-select>
  43. </el-form-item>
  44. </el-col>
  45. <el-col v-if="formatData(formInline.algorithmtype) != 'js'" :span="24">
  46. <el-form-item prop="targetsource" label="数据源目标">
  47. <el-input size="small" v-model="tableForm.targetsource"></el-input>
  48. </el-form-item>
  49. </el-col>
  50. <el-col :span="24">
  51. <el-form-item prop="executionorder" label="执行排序">
  52. <el-input size="small" v-model="tableForm.executionorder"></el-input>
  53. </el-form-item>
  54. </el-col>
  55. <el-col :span="24">
  56. <el-form-item prop="algorithmdescription" label="算法说明">
  57. <el-input size="small" v-model="tableForm.algorithmdescription"></el-input>
  58. </el-form-item>
  59. </el-col>
  60. <el-col :span="24">
  61. <el-form-item prop="computingexpression" label="计算表达式">
  62. <el-input size="small" type="textarea" v-model="tableForm.computingexpression"></el-input>
  63. </el-form-item>
  64. </el-col>
  65. <el-col :span="24">
  66. <el-form-item prop="preconditions" label="执行条件">
  67. <el-input size="small" type="textarea" v-model="tableForm.preconditions"></el-input>
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="24">
  71. <el-form-item prop="preparameterset" label="前置条件参数">
  72. <el-input size="small" type="textarea" v-model="tableForm.preparameterset"></el-input>
  73. </el-form-item>
  74. </el-col>
  75. </el-row>
  76. </el-form>
  77. <el-table :data="tableData" border style="width: 100%">
  78. <el-table-column v-for="col in tableCols" :key="col.pagecode" :prop="col.pagecode" :label="col.pagename" :width="col.displaywidth+'px'">
  79. <template slot-scope="scope">
  80. <el-input size="small" v-model="scope.row[col.pagecode]" placeholder="请输入参数名" />
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. </div>
  85. </PublicPageDialog>
  86. </div>
  87. </template>
  88. <script>
  89. import PublicPageDialog from '@/components/PublicPageDialog'
  90. import nodeBtn from './accessPageNodeBtn.vue'
  91. import { Query, newData, modifyData, moveData } from "@/api/webApi"
  92. import { formatChange, getTableCols } from '@/utils/validate'
  93. export default {
  94. name: 'AccessPageNode',
  95. components: { nodeBtn, PublicPageDialog },
  96. props: {
  97. msgContent: {
  98. type: Object,
  99. default: () => new Object()
  100. }
  101. },
  102. data () {
  103. return {
  104. loading: false,
  105. tabFlag: false,
  106. nodeItems: [
  107. {
  108. algorithmname: '开始',
  109. isLine: true,
  110. isDel: false
  111. }
  112. ],
  113. formInline: {
  114. algorithmtype: '',
  115. },
  116. tableForm: {
  117. serviceid: '',
  118. preconditions: '',
  119. algorithmtype: '',
  120. algorithmname: '',
  121. algorithmsourcelibraryid: '',
  122. executionorder: '',
  123. targetsource: '',
  124. datasourceid: '',
  125. computingexpression: '',
  126. algorithmdescription: '',
  127. preparameterset: ''
  128. },
  129. nodeIndex: '',
  130. tableCols: [],
  131. selectType: [],
  132. selectAlgorithm: [],
  133. selectSource: [],
  134. radio3: '',
  135. dialogTitle: '添加步骤',
  136. advancedDrawer: false,
  137. tableDrawer: false,
  138. tableData: [],
  139. pageServiceId: 15,
  140. pageTableId: 24,
  141. type: 'add'
  142. }
  143. },
  144. watch: {
  145. radio3: {
  146. handler (val) {
  147. if (val) {
  148. this.tabFlag = true
  149. // this.getSelectData('datatable', 20, { superiorid: val })
  150. }
  151. },
  152. deep: true
  153. },
  154. msgContent: {
  155. handler (row) {
  156. this.setTableData(row)
  157. },
  158. deep: true,
  159. immediate: true
  160. },
  161. },
  162. mounted () {
  163. this.tableCols = getTableCols(233)
  164. this.getSelectData('algorithmtype', 20, { type: 'category' })
  165. },
  166. methods: {
  167. async getSelectData (pagecode, serviceid, datacontent) {
  168. this.loading = true
  169. try {
  170. datacontent = { filter: datacontent }
  171. const { code, returnData } = await Query({ serviceid: serviceid, datacontent, event: '0', page: 1, size: 9999 })
  172. if (code && returnData?.length) {
  173. this.setFormSelectData(pagecode, returnData)
  174. }
  175. } catch (error) {
  176. this.$message.error(error)
  177. }
  178. this.loading = false
  179. },
  180. //设置数据
  181. setTableData (row) {
  182. if (row && Object.keys(row).length) {
  183. const { passparameters } = row
  184. const filterItem = this.formatDefault(passparameters, row)
  185. if (!Object.keys(filterItem).length) return
  186. this.nodeItems = this.nodeItems.splice(0, 1)
  187. this.getSelectData('nodedata', 15, filterItem)
  188. }
  189. },
  190. //格式化传递参数数据
  191. formatDefault (item, data = {}) {
  192. if (typeof item != 'string') return {}
  193. const filterItem = {}
  194. const parameters = item.replace('{', '').replace('}', '')
  195. const parametersSplit = parameters?.split(',')
  196. parametersSplit.map(item => {
  197. const [key, val] = item?.split(':')
  198. filterItem[key] = data[val]
  199. })
  200. return filterItem
  201. },
  202. //获取表单下拉数据
  203. changeSelect (name, code) {
  204. switch (name) {
  205. case 'algorithmtype':
  206. const nstr = _.cloneDeep(code).toString().toLocaleLowerCase()
  207. const item = this.selectType.filter(item => item.code == code)
  208. if (!item?.length) return
  209. const id = item[0].id
  210. this.getSelectData('algorithmname', 20, { superiorid: id })
  211. this.getSelectData('datasourceid', 12, { datasourcetype: code })
  212. break;
  213. default:
  214. break;
  215. }
  216. },
  217. setFormSelectData (name, returnData) {
  218. switch (name) {
  219. case 'serviceid':
  220. this.selectService = [...returnData]
  221. break;
  222. case 'algorithmtype':
  223. this.selectType = [...returnData]
  224. break;
  225. case 'algorithmname':
  226. this.selectAlgorithm = [...returnData]
  227. break;
  228. case 'datasourceid':
  229. this.selectSource = [...returnData]
  230. break
  231. case 'datatable':
  232. this.tableData = [...returnData]
  233. break
  234. case 'nodedata':
  235. //executionorder
  236. const newItems = _.orderBy([...returnData], ['executionorder'], ['desc'])
  237. this.nodeItems = [...this.nodeItems, ...newItems]
  238. break
  239. default:
  240. break;
  241. }
  242. },
  243. //步骤新增
  244. handleAdd (obj) {
  245. this.type = 'add'
  246. this.advancedDrawer = obj.flag
  247. this.tableData = []
  248. },
  249. //步骤编辑
  250. handleEdit (item) {
  251. const data = _.cloneDeep(item)
  252. const { algorithmlibraryid } = data
  253. if (!algorithmlibraryid) return
  254. this.advancedDrawer = true
  255. this.tabFlag = true
  256. this.tableForm = data
  257. this.getSelectData('datatable', 24, { algorithmlibraryid })
  258. },
  259. //步骤删除
  260. handleDel (obj) {
  261. this.type = 'del'
  262. const item = _.cloneDeep(obj)
  263. const { algorithmname } = item
  264. this.$confirm(`确认要删除 ${algorithmname} 这条信息吗?`, '提示', {
  265. confirmButtonText: '确定',
  266. cancelButtonText: '取消',
  267. type: 'warning'
  268. }).then(() => {
  269. this.generalDataReception(3, this.formatDataNull(item), 'algorithmlibraryid')
  270. }).catch(() => {
  271. this.$message({
  272. type: 'info',
  273. message: '已取消删除'
  274. });
  275. });
  276. },
  277. //弹框关闭
  278. advancedClose () {
  279. this.clearState()
  280. },
  281. //弹框确定
  282. advancedTable () {
  283. console.log(this.tableData)
  284. return
  285. const data = _.cloneDeep(this.tableForm)
  286. data.serviceid = this.msgContent.serviceid
  287. data.algorithmtype = this.formInline.algorithmtype
  288. data.algorithmsourcelibraryid = this.radio3
  289. const event = this.type == 'add' ? 1 : this.type == 'edit' ? 2 : 3
  290. this.generalDataReception(event, this.formatDataNull(data))
  291. },
  292. //状态清除
  293. clearState () {
  294. this.formInline.algorithmtype = ''
  295. this.radio3 = ''
  296. this.selectAlgorithm = []
  297. for (const key in this.tableForm) {
  298. if (Object.hasOwnProperty.call(this.tableForm, key)) {
  299. this.tableForm[key] = null
  300. }
  301. }
  302. this.advancedDrawer = false
  303. this.tabFlag = false
  304. this.loading = false
  305. this.tableDrawer = false
  306. },
  307. formatDataNull (params) {
  308. const obj = _.cloneDeep(params)
  309. for (const key in obj) {
  310. if (Object.hasOwnProperty.call(obj, key)) {
  311. const element = obj[key]
  312. if (!element) {
  313. obj[key] = null
  314. }
  315. }
  316. }
  317. return obj
  318. },
  319. //表格-增/删/改
  320. async generalDataReception (event, data, key) {
  321. try {
  322. const params = {
  323. serviceid: this.pageServiceId,
  324. datacontent: formatChange(data, event, key),
  325. event: `${event}`,
  326. };
  327. const { code } =
  328. event == 1
  329. ? await newData(params)
  330. : event == 2
  331. ? await modifyData(params)
  332. : await moveData(params);
  333. if (code == 0) {
  334. this.$message.success("操作成功")
  335. this.restTable()
  336. this.clearState()
  337. } else {
  338. this.$message.error("操作失败")
  339. this.clearState()
  340. }
  341. } catch (error) {
  342. this.clearState()
  343. console.log(error)
  344. }
  345. },
  346. restTable () {
  347. this.setTableData(this.msgContent)
  348. },
  349. formatData (name) {
  350. return typeof name == 'string' ? name.toLocaleLowerCase() : name
  351. },
  352. }
  353. }
  354. </script>
  355. <style lang="scss" scoped>
  356. .accessPageNode {
  357. display: flex;
  358. width: 100%;
  359. height: 100%;
  360. justify-content: center;
  361. align-items: center;
  362. overflow-y: scroll;
  363. &-items {
  364. text-align: center;
  365. }
  366. .advancedNode {
  367. text-align: left;
  368. }
  369. }
  370. </style>