index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <div class="view-table-content">
  3. <div style="width: 100%">
  4. <div class="view-dataType-title">
  5. <div class="view-dataType-title-btn">
  6. <el-button type="success" @click="openDialog()">新增</el-button>
  7. <el-button type="warning" @click="remove(tableCheckItems)" :disabled="tableCheckItems.length == 0">删除</el-button>
  8. </div>
  9. <div class="view-dataType-title-search">
  10. <el-input placeholder="请输入名称" v-model="keyWordData" class="input1">
  11. <el-button slot="append" icon="el-icon-search" @click="searchClick"></el-button>
  12. </el-input>
  13. </div>
  14. </div>
  15. <div class="view-dataType-table">
  16. <LTable ref="table" @selection-change="selection" :defaultFetch="false" :fetch="fetch" :columns="columns" :dataSource="tableData" :options="options" :pagination="tableRequset"></LTable>
  17. </div>
  18. <!-- 添加或修改模型信息对话框 -->
  19. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
  20. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  21. <el-form-item label="模型名称" prop="name">
  22. <el-input v-model="form.name" placeholder="请输入模型名称" />
  23. </el-form-item>
  24. <el-form-item label="模型类型" prop="type">
  25. <el-select v-model="form.type" placeholder="请选择模型类型">
  26. <el-option v-for="item in $enumData.agloModelList" :key="item.key" :label="item.name" :value="item.key" />
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item label="模型链接" prop="url">
  30. <el-input v-model="form.url" placeholder="请输入模型链接" />
  31. </el-form-item>
  32. <el-form-item v-if="['5'].includes(form.type)" label="参数特征" prop="paramType">
  33. <el-select v-model="form.paramType" filterable allow-create default-first-option placeholder="请选择参数特征">
  34. <el-option v-for="item in paramTypeData" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"> </el-option>
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item v-show="['5', '6'].includes(form.type)" label="机型" prop="aircraftType">
  38. <treeselect :value="form.aircraftType" :normalizer="aircraftTypeNormalizer" :options="aircraftTypeTreeData" :show-count="true" placeholder="请选择机型" @select="aircraftTypeChange" />
  39. </el-form-item>
  40. <el-form-item v-show="['5', '6'].includes(form.type)" label="部件" prop="partId">
  41. <treeselect noOptionsText="该机型暂无构型信息,请在构型管理中添加" :value="form.partId" :normalizer="normalizer" :options="partsData" :show-count="true" placeholder="请选择部件" @select="partIdSelect" />
  42. </el-form-item>
  43. <el-form-item label="参数" prop="param">
  44. <el-input type="textarea" :rows="2" v-model="form.param" placeholder="请输入参数" />
  45. </el-form-item>
  46. <el-form-item label="数据列" prop="columnData">
  47. <el-input type="textarea" :rows="3" v-model="form.columnData" placeholder="请输入数据列" />
  48. </el-form-item>
  49. <el-form-item v-if="dialogTitle === '编辑'" label="状态" prop="status">
  50. <el-switch v-model="form.status" active-color="#13ce66" active-value="1" inactive-value="0"> </el-switch>
  51. </el-form-item>
  52. <el-form-item label="备注" prop="remark">
  53. <el-input type="textarea" :rows="2" v-model="form.remark" placeholder="请输入备注" />
  54. </el-form-item>
  55. </el-form>
  56. <span slot="footer" class="dialog-footer">
  57. <el-button @click="handleClose">取 消</el-button>
  58. <el-button type="primary" @click="submit">确 定</el-button>
  59. </span>
  60. </el-dialog>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import { getModel, addModel, updateModel, removeModel } from '@/api/als/model'
  66. import { deepClone, debounce } from '@/utils/index'
  67. import Treeselect from '@riophae/vue-treeselect'
  68. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  69. import { handleTree } from '../utils/common'
  70. import { getAirConfiguration } from '@/api/als/airConfiguration'
  71. import { getAircaftTypeAndModelTree } from '@/api/als/sideTree'
  72. import { getDict } from '@/api/dict'
  73. import { addData } from '@/api/system/dict/data'
  74. import { getAircaftModelAll } from '@/api/als/aircraft'
  75. export default {
  76. name: 'Model',
  77. components: { Treeselect },
  78. data() {
  79. // 这里存放数据
  80. return {
  81. dialogTitle: '新增',
  82. dialogVisible: false,
  83. keyWordData: '',
  84. aircaftModelIdList: [],
  85. searchValue: '',
  86. columns: [
  87. {
  88. prop: 'name',
  89. label: '模型名称'
  90. },
  91. {
  92. prop: 'type',
  93. label: '模型类型',
  94. render: (h, params) => {
  95. const matchedItem = this.$enumData.agloModelList.find((item) => params.row.type === item.key)
  96. if (matchedItem) {
  97. return h('span', matchedItem.name)
  98. } else {
  99. return h('span', {}, '')
  100. }
  101. }
  102. },
  103. {
  104. prop: 'url',
  105. label: '模型链接'
  106. },
  107. {
  108. prop: 'paramType',
  109. label: '参数特征'
  110. },
  111. {
  112. prop: 'aircraftType',
  113. label: '机型',
  114. render: (h, params) => {
  115. const matchedItem = this.aircaftModelAll.find((item) => params.row.aircraftType === item.aircaftModelId)
  116. if (matchedItem) {
  117. return h('span', matchedItem.aircaftModelName)
  118. } else {
  119. return h('span', {}, '')
  120. }
  121. }
  122. },
  123. {
  124. prop: 'partId',
  125. label: '部件',
  126. render: (h, params) => {
  127. const matchedItem = this.allAirConfig.find((item) => params.row.partId === item.id)
  128. if (matchedItem) {
  129. return h('span', matchedItem.name)
  130. } else {
  131. return h('span', {}, '')
  132. }
  133. }
  134. },
  135. {
  136. prop: 'param',
  137. label: '模型参数'
  138. },
  139. {
  140. prop: 'columnData',
  141. label: '数据列'
  142. },
  143. {
  144. prop: 'status',
  145. label: '状态',
  146. render: (h, params) => {
  147. if (params.row.status == 0) {
  148. return h('span', { class: 'warning-state' }, '禁用')
  149. } else {
  150. return h('span', { class: 'success-state' }, '启用')
  151. }
  152. }
  153. },
  154. {
  155. prop: 'remark',
  156. label: '备注'
  157. },
  158. {
  159. button: true,
  160. label: '操作',
  161. width: '240px',
  162. group: [
  163. {
  164. name: '编辑',
  165. type: 'text',
  166. round: false,
  167. plain: false,
  168. onClick: (row, index, scope) => {
  169. this.handUpdate(row)
  170. }
  171. },
  172. {
  173. name: '删除',
  174. type: 'text',
  175. round: false,
  176. plain: false,
  177. onClick: (row, index, scope) => {
  178. this.remove([row])
  179. }
  180. }
  181. ]
  182. }
  183. ],
  184. options: {
  185. stripe: false, // 斑马纹
  186. mutiSelect: true, // 多选框
  187. index: false, // 显示序号, 多选则 mutiSelect
  188. loading: false, // 表格动画
  189. initTable: false, // 是否一挂载就加载数据
  190. border: true,
  191. height: 'calc(100vh - 300px)'
  192. },
  193. tableCheckItems: [],
  194. tableData: [],
  195. tableRequset: {
  196. total: 0,
  197. pageIndex: 1,
  198. pageSize: 20,
  199. searchValue: ''
  200. },
  201. form: {
  202. id: '',
  203. name: '',
  204. type: '',
  205. url: '',
  206. paramType: null,
  207. aircraftType: null,
  208. partId: null,
  209. param: '',
  210. columnData: '',
  211. status: '1',
  212. remark: ''
  213. },
  214. debounceFn: debounce(this.fetch, 500),
  215. partsData: [],
  216. aircraftTypeTreeData: [],
  217. allAirConfig: [],
  218. rules: {
  219. name: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
  220. type: [{ required: true, message: '模型类型不能为空', trigger: 'change' }],
  221. url: [{ required: true, message: '模型链接不能为空', trigger: 'blur' }],
  222. paramType: [{ required: true, message: '参数特征不能为空', trigger: 'change' }],
  223. aircraftType: [{ required: true, message: '机型不能为空', trigger: 'change' }],
  224. columnData: [{ required: true, message: '数据列不能为空', trigger: 'blur' }],
  225. partId: [{ required: true, message: '部件不能为空', trigger: 'change' }]
  226. },
  227. paramTypeData: [],
  228. aircaftModelAll: []
  229. }
  230. },
  231. watch: {
  232. keyWord() {
  233. this.tableRequset.pageIndex = 1
  234. this.debounceFn()
  235. }
  236. },
  237. mounted() {
  238. this.getDict()
  239. this.getModelAPI()
  240. this.getPartData()
  241. },
  242. methods: {
  243. async getDict() {
  244. const { data } = await getDict('als_model_params_character')
  245. this.paramTypeData = data
  246. const getAircaftModelAllParams = {
  247. aircaftTypeCode: '',
  248. aircaftTypeId: '',
  249. queryParam: ''
  250. }
  251. const { data: data1 } = await getAircaftModelAll(getAircaftModelAllParams)
  252. this.aircaftModelAll = data1
  253. },
  254. async getPartData() {
  255. try {
  256. const { data } = await getAircaftTypeAndModelTree()
  257. const { data: airConfigData } = await getAirConfiguration()
  258. this.allAirConfig = airConfigData
  259. this.aircraftTypeTreeData = data[0].children
  260. } catch (error) {}
  261. },
  262. normalizer(node) {
  263. if (node.children && !node.children.length) {
  264. delete node.children
  265. }
  266. return {
  267. id: node.id,
  268. label: node.name,
  269. children: node.children
  270. }
  271. },
  272. aircraftTypeNormalizer(node) {
  273. if (node.children && !node.children.length) {
  274. delete node.children
  275. }
  276. return {
  277. id: node.id,
  278. label: node.label,
  279. children: node.children
  280. }
  281. },
  282. aircraftTypeChange(node) {
  283. this.form.aircraftType = node.id
  284. this.form.partId = null
  285. this.getAirConfigurationAPI({ aircraftType: this.form.aircraftType })
  286. },
  287. async getAirConfigurationAPI(params) {
  288. try {
  289. const { data } = await getAirConfiguration(params)
  290. const treeData = handleTree(data, 'id')
  291. this.partsData = treeData
  292. } catch (error) {}
  293. },
  294. partIdSelect(node) {
  295. this.form.partId = node.id
  296. },
  297. async removeModelAPI(params) {
  298. try {
  299. const { code } = await removeModel(params)
  300. if (code === 200) {
  301. this.$message({
  302. type: 'success',
  303. message: '操作成功!'
  304. })
  305. await this.getModelAPI()
  306. this.handleClose()
  307. }
  308. } catch (error) {}
  309. },
  310. async getModelAPI(params) {
  311. if (this.$refs.table) this.$refs.table.clearSelection()
  312. const { pageSize, pageIndex } = this.tableRequset
  313. const {
  314. data: { list, total }
  315. } = await getModel({ pageSize, pageNum: pageIndex, ...params })
  316. this.tableData = list
  317. this.tableRequset.total = total
  318. },
  319. fetch() {
  320. this.getModelAPI()
  321. },
  322. async searchClick() {
  323. this.getModelAPI({ name: this.keyWordData })
  324. },
  325. async addModelAPI() {
  326. try {
  327. delete this.form.aircaftModelName
  328. const { code } = await addModel({ ...this.form })
  329. if (code === 200) {
  330. this.$message({
  331. type: 'success',
  332. message: '操作成功!'
  333. })
  334. this.handleClose()
  335. this.getModelAPI()
  336. }
  337. } catch (error) {}
  338. },
  339. async updateModelAPI() {
  340. try {
  341. const { code } = await updateModel({ ...this.form })
  342. if (code === 200) {
  343. this.$message({
  344. type: 'success',
  345. message: '操作成功!'
  346. })
  347. this.handleClose()
  348. this.getModelAPI()
  349. }
  350. } catch (error) {}
  351. },
  352. openDialog() {
  353. this.dialogTitle = '新增'
  354. this.dialogVisible = true
  355. },
  356. handleClose() {
  357. this.dialogVisible = false
  358. this.form = {
  359. id: '',
  360. name: '',
  361. type: '',
  362. url: '',
  363. paramType: null,
  364. aircraftType: null,
  365. partId: null,
  366. param: '',
  367. columnData: '',
  368. status: '1',
  369. remark: ''
  370. }
  371. },
  372. handUpdate(row) {
  373. this.dialogTitle = '编辑'
  374. this.form = deepClone(row)
  375. if (['5', '6'].includes(this.form.type)) {
  376. const item = this.allAirConfig.find((item) => item.id === this.form.partId)
  377. this.form.aircraftType = item.aircraftType
  378. this.getAirConfigurationAPI({ aircraftType: this.form.aircraftType })
  379. }
  380. this.dialogVisible = true
  381. },
  382. submit() {
  383. const isExist = this.paramTypeData.find((item) => {
  384. return item.dictLabel === this.form.paramType
  385. })
  386. if (this.form.paramType && !isExist) {
  387. const sortData = Math.max.apply(
  388. Math,
  389. this.paramTypeData.map((item) => {
  390. return item.dictSort
  391. })
  392. )
  393. const data = {
  394. dictType: 'als_model_params_character',
  395. dictLabel: this.form.paramType,
  396. dictValue: this.form.paramType,
  397. dictSort: sortData + 1,
  398. status: '0'
  399. }
  400. addData(data).then((response) => {
  401. if (response.code !== '200') {
  402. this.$message({
  403. type: 'warning',
  404. message: '模型参数特征未保存成功'
  405. })
  406. // useMessage('warning', '模型参数特征未保存成功')
  407. }
  408. })
  409. }
  410. switch (this.dialogTitle) {
  411. case '编辑':
  412. this.updateModelAPI()
  413. break
  414. case '新增':
  415. this.addModelAPI()
  416. break
  417. }
  418. },
  419. selection(val) {
  420. this.tableCheckItems = val
  421. },
  422. remove(row) {
  423. this.$confirm('是否删除该模型', '提示', {
  424. confirmButtonText: '确定',
  425. cancelButtonText: '取消',
  426. type: 'warning'
  427. })
  428. .then(() => {
  429. this.removeModelAPI(row.map((e) => e.id))
  430. })
  431. .catch(() => {})
  432. }
  433. }
  434. }
  435. </script>
  436. <style lang="scss" scoped>
  437. @import '../index.scss';
  438. </style>