Index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索表单 -->
  4. <div class="filter-container">
  5. <span>
  6. <span>模型名称:</span>
  7. <el-input v-model="queryParams.model.name" placeholder="请输入名称" style="width: 150px;" size="medium"/>
  8. </span>
  9. <span class="rearchItem">
  10. <span>启用状态:</span>
  11. <el-select v-model="queryParams.model.status" placeholder="请选择启用状态" size="medium" style="width: 150px;">
  12. <el-option
  13. v-for="item in statusList"
  14. :key="item.value"
  15. :label="item.label"
  16. :value="item.value">
  17. </el-option>
  18. </el-select>
  19. </span>
  20. <span class="rearchItem">
  21. <span>类型:</span>
  22. <el-select style="width:150px;" placeholder="请选择类型" v-model="queryParams.model.nodeType" value>
  23. <el-option :key="index" :label="item" :value="key" v-for="(item, key, index) in dicts.MODEL_NODE_TYPE" />
  24. </el-select>
  25. </span>
  26. <span class="rearchItem">
  27. <el-button plain type="primary" icon="el-icon-search" size="medium" @click="search">
  28. {{ $t("table.search") }}
  29. </el-button>
  30. <el-button plain type="warning" icon="el-icon-refresh" size="medium" @click="reset">
  31. {{ $t("table.reset") }}
  32. </el-button>
  33. </span>
  34. </div>
  35. <el-row class="filter-container">
  36. <el-col>
  37. <el-button type="primary" icon="el-icon-plus" size="medium" @click="add">
  38. {{ $t("table.add") }}
  39. </el-button>
  40. <el-button type="success" icon="el-icon-edit" size="medium" @click="editOne">
  41. {{ $t("common.edit") }}
  42. </el-button>
  43. <el-button type="danger" icon="el-icon-delete" size="medium" @click="batchDelete">
  44. {{ $t("table.delete") }}
  45. </el-button>
  46. <el-button type="primary" icon="el-icon-check" size="medium" @click="updateActiveStatus('1')">
  47. {{ $t("table.qiyong") }}
  48. </el-button>
  49. <el-button type="primary" icon="el-icon-warning-outline" size="medium" @click="updateActiveStatus('0')">
  50. {{ $t("table.dongjie") }}
  51. </el-button>
  52. </el-col>
  53. </el-row>
  54. <el-table
  55. :key="tableKey"
  56. ref="table"
  57. v-loading="loading"
  58. :data="tableData.records"
  59. border
  60. fit
  61. row-key="id"
  62. style="width: 100%;"
  63. @filter-change="filterChange"
  64. @selection-change="onSelectChange"
  65. @sort-change="sortChange"
  66. @cell-click="cellClick"
  67. >
  68. <el-table-column align="center" type="selection" width="40px" :reserve-selection="true" />
  69. <el-table-column prop="name" label="模型名称" :show-overflow-tooltip="true" width="200px"></el-table-column>
  70. <el-table-column prop="no" label="编号" :show-overflow-tooltip="true" width="120px"></el-table-column>
  71. <el-table-column prop="status" label="状态" align="center" width="90px">
  72. <template slot-scope="{ row }">
  73. <el-tag :type="row.status=='1' ? 'success' : 'info'">
  74. {{ row.status=='1' ? '启用' : '停用' }}
  75. </el-tag>
  76. </template>
  77. </el-table-column>
  78. <el-table-column prop="nodeType.data" label="类型" :show-overflow-tooltip="true" width="100px"></el-table-column>
  79. <el-table-column prop="brandDesc" label="品牌" :show-overflow-tooltip="true" width="150px"></el-table-column>
  80. <el-table-column prop="specificationDesc" label="规格" :show-overflow-tooltip="true" width="200px"></el-table-column>
  81. <el-table-column prop="remark" label="描述" :show-overflow-tooltip="true" width="250px"></el-table-column>
  82. <el-table-column
  83. :label="$t('table.operation')"
  84. fixed="right"
  85. align="center"
  86. column-key="operation"
  87. width="150px"
  88. >
  89. <template slot-scope="{ row }">
  90. <el-tooltip class="item" content="查看详情" effect="dark" placement="top-start">
  91. <i
  92. class="el-icon-view table-operation"
  93. style="color: #87d068;"
  94. @click="viewDetail(row)"
  95. />
  96. </el-tooltip>
  97. <!--<el-tooltip class="item" content="查看详情" effect="dark" placement="top-start">
  98. <i
  99. class="el-icon-view table-operation"
  100. style="color: #87d068;"
  101. @click="view(row)"
  102. />
  103. </el-tooltip>-->
  104. <el-tooltip class="item" content="修改" effect="dark" placement="top-start">
  105. <i
  106. class="el-icon-edit table-operation"
  107. style="color: #2db7f5;"
  108. @click="edit(row)"
  109. />
  110. </el-tooltip>
  111. <el-tooltip class="item" content="删除" effect="dark" placement="top-start">
  112. <i
  113. class="el-icon-delete table-operation"
  114. style="color: #f50;"
  115. @click="singleDelete(row)"
  116. />
  117. </el-tooltip>
  118. <el-tooltip class="item" content="冻结" effect="dark" placement="top-start">
  119. <i
  120. class="el-icon-warning-outline table-operation"
  121. style="color: #f50;"
  122. @click="dongJieRow(row)"
  123. />
  124. </el-tooltip>
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. <pagination
  129. v-show="tableData.total > 0"
  130. :limit.sync="queryParams.size"
  131. :page.sync="queryParams.current"
  132. :total="Number(tableData.total)"
  133. @pagination="fetch"
  134. />
  135. <tenant-edit
  136. ref="edit"
  137. :dialog-visible="dialog.isVisible"
  138. :title="dialog.title"
  139. @close="editClose"
  140. @success="editSuccess"
  141. />
  142. <tenant-view
  143. ref="view"
  144. :dialog-visible="tenantViewVisible"
  145. @close="viewClose"
  146. />
  147. <el-dialog
  148. v-el-drag-dialog
  149. :close-on-click-modal="false"
  150. :close-on-press-escape="true"
  151. title="预览"
  152. width="80%"
  153. top="50px"
  154. :visible.sync="preview.isVisible"
  155. >
  156. <el-scrollbar>
  157. <div v-html="preview.context" />
  158. </el-scrollbar>
  159. </el-dialog>
  160. </div>
  161. </template>
  162. <script>
  163. import Pagination from "@/components/Pagination"
  164. import TenantEdit from "./components/Edit"
  165. import TenantView from "./components/View"
  166. // 【模型管理】-API
  167. import moduleMgrApi from "@/api/enterpriseMgr/moduleMgr"
  168. import elDragDialog from '@/directive/el-drag-dialog'
  169. import { downloadFile, initEnums, initQueryParams } from '@/utils/commons'
  170. // 共通工具方法(字典分解)
  171. import { convertEnum } from '@/utils/utils'
  172. // 查询【字典】的共通方法
  173. import { initDicts } from '@/utils/commons'
  174. export default {
  175. name: "ModuleMgr",
  176. directives: { elDragDialog },
  177. components: { Pagination, TenantEdit, TenantView },
  178. data () {
  179. return {
  180. statusList: [], // 在模型状态数据
  181. dicts: {
  182. MODEL_CATEGORY: {}, //分类
  183. MODEL_NODE_TYPE: {}, //节点类型
  184. MODEL_NET_MODE: {}, //联网方式
  185. MODEL_JOIN_AGREEMENT: {}, //接入盒子协议
  186. MODEL_CNC_SYSTEM: {}, //cnc数控系统
  187. },
  188. dialog: {
  189. isVisible: false,
  190. title: ""
  191. },
  192. preview: {
  193. isVisible: false,
  194. context: ''
  195. },
  196. tenantViewVisible: false,
  197. tableKey: 0,
  198. queryParams: initQueryParams({}),
  199. selection: [],
  200. loading: false,
  201. tableData: {
  202. total: 0
  203. },
  204. enums: {
  205. TenantTypeEnum: {},
  206. TenantStatusEnum: {}
  207. }
  208. }
  209. },
  210. // 实例已经在内存中创建好,此时data和methods已将ok,如果要操作data中的数据或是调用methods中的方法,最早只能在created中操作
  211. created() {
  212. // 调用常量-初始化值
  213. this.statusList = this.$constWKS.STATUSLIST;
  214. },
  215. computed: {
  216. currentUser () {
  217. return this.$store.state.account.user
  218. },
  219. categoryList() {
  220. return convertEnum(this.dicts.MODEL_CATEGORY)
  221. },
  222. nodeTypeList() {
  223. return convertEnum(this.dicts.MODEL_NODE_TYPE)
  224. },
  225. netModeList() {
  226. return convertEnum(this.dicts.MODEL_NET_MODE)
  227. },
  228. jionAgreementList() {
  229. return convertEnum(this.dicts.MODEL_JOIN_AGREEMENT)
  230. },
  231. cncSystemList() {
  232. return convertEnum(this.dicts.MODEL_CNC_SYSTEM)
  233. }
  234. },
  235. mounted () {
  236. // 初始化,【字典】数据
  237. initDicts(['MODEL_CATEGORY', 'MODEL_NODE_TYPE', 'MODEL_NET_MODE', 'MODEL_JOIN_AGREEMENT','MODEL_CNC_SYSTEM'], this.dicts);
  238. this.fetch()
  239. },
  240. methods: {
  241. // 【查看详情】按钮-事件
  242. viewDetail(row){
  243. // 把【模型管理】对象,添加到路由传值
  244. // 调用全局挂载的方法
  245. this.$store.dispatch('tagsView/delView', this.$route).then(res => {
  246. this.$router.push({ path: '/internetCenter/moduleDetail', query: row}) //带参跳转
  247. })
  248. },
  249. // 【启用/冻结】按钮-事件
  250. updateActiveStatus(status){
  251. if (!this.selection.length) {
  252. this.$message({
  253. message: "请至少选择一条数据!",
  254. type: "warning"
  255. })
  256. return
  257. }
  258. if (this.selection.length > 1) {
  259. this.$message({
  260. message: "请只能选择一条数据!",
  261. type: "warning"
  262. })
  263. return
  264. }
  265. // 传值
  266. let obj = {};
  267. obj = this.selection[0];
  268. obj.status = status;
  269. // 调用接口后的提示信息
  270. let msg = "冻结成功!";
  271. if(status == "1"){
  272. msg = "启用成功!";
  273. }
  274. moduleMgrApi.updateActiveStatus(obj).then(response => {
  275. if (response.status == 200) {
  276. this.$message({
  277. message: msg,
  278. type: "success"
  279. })
  280. // 重新查询列表数据
  281. this.search()
  282. }
  283. })
  284. },
  285. // 【冻结】-Table的Row操作事件
  286. dongJieRow(row) {
  287. // 传值
  288. let obj = {};
  289. obj = row;
  290. obj.status = "0";
  291. moduleMgrApi.updateActiveStatus(obj).then(response => {
  292. if (response.status == 200) {
  293. this.$message({
  294. message: "冻结成功!",
  295. type: "success"
  296. })
  297. // 重新查询列表数据
  298. this.search()
  299. }
  300. })
  301. },
  302. viewClose () {
  303. this.tenantViewVisible = false
  304. },
  305. editClose () {
  306. this.dialog.isVisible = false
  307. },
  308. editSuccess () {
  309. this.search()
  310. },
  311. onSelectChange (selection) {
  312. this.selection = selection
  313. },
  314. search () {
  315. this.fetch({
  316. ...this.queryParams
  317. })
  318. },
  319. reset () {
  320. this.queryParams = initQueryParams({})
  321. this.$refs.table.clearSort()
  322. this.$refs.table.clearFilter()
  323. this.search()
  324. },
  325. exportExcelPreview () {
  326. if (this.queryParams.timeRange) {
  327. this.queryParams.map.createTime_st = this.queryParams.timeRange[0]
  328. this.queryParams.map.createTime_ed = this.queryParams.timeRange[1]
  329. }
  330. this.queryParams.map.fileName = '导出模型数据'
  331. moduleMgrApi.preview(this.queryParams).then(response => {
  332. const res = response.data
  333. this.preview.isVisible = true
  334. this.preview.context = res.data
  335. })
  336. },
  337. exportExcel () {
  338. if (this.queryParams.timeRange) {
  339. this.queryParams.map.createTime_st = this.queryParams.timeRange[0]
  340. this.queryParams.map.createTime_ed = this.queryParams.timeRange[1]
  341. }
  342. this.queryParams.map.fileName = '导出模型数据'
  343. moduleMgrApi.export(this.queryParams).then(response => {
  344. downloadFile(response)
  345. })
  346. },
  347. add () {
  348. this.$refs.edit.type = "add"
  349. // 把数据,设置到【查看】弹出组件
  350. this.$refs.edit.setTenant(false, this.dicts)
  351. this.dialog.title = this.$t("common.add")
  352. this.dialog.isVisible = true
  353. },
  354. singleDelete (row) {
  355. this.$confirm("删除模型数据后,会将模型数据全部删除,确认删除?", this.$t("common.tips"), {
  356. distinguishCancelAndClose: true,
  357. confirmButtonText: "确认",
  358. cancelButtonText: "取消",
  359. type: "warning"
  360. }).then(() => {
  361. this.$refs.table.clearSelection()
  362. this.$refs.table.toggleRowSelection(row, true)
  363. // 可以多个删除
  364. // this.batchDelete()
  365. // 单个删除
  366. this.deleteOnly(row.id)
  367. }).catch(() => {})
  368. },
  369. batchDelete () {
  370. if (!this.selection.length) {
  371. this.$message({
  372. message: this.$t("tips.noDataSelected"),
  373. type: "warning"
  374. })
  375. return
  376. }
  377. if (this.selection.length > 1) {
  378. this.$message({
  379. message: "请只能选择一条数据!",
  380. type: "warning"
  381. })
  382. return
  383. }
  384. this.$confirm("删除模型数据后,会将模型数据全部删除,确认删除?", this.$t("common.tips"), {
  385. distinguishCancelAndClose: true,
  386. confirmButtonText: "确认",
  387. cancelButtonText: "取消",
  388. type: "warning"
  389. }).then(() => {
  390. /*const ids = []
  391. this.selection.forEach(item => {
  392. ids.push(item.id)
  393. })
  394. // 可以多个删除
  395. this.delete(ids)*/
  396. // 单个删除
  397. this.deleteOnly(this.selection[0].id)
  398. }).catch(() => {})
  399. },
  400. clearSelections () {
  401. this.$refs.table.clearSelection()
  402. },
  403. delete (ids) {
  404. moduleMgrApi.remove({ ids: ids }).then(response => {
  405. const res = response.data
  406. if (res.isSuccess) {
  407. this.$message({
  408. message: this.$t("tips.deleteSuccess"),
  409. type: "success"
  410. })
  411. this.search()
  412. // 清理已经删除的数据
  413. this.$refs.table.clearSelection()
  414. }
  415. })
  416. },
  417. // 每次只删除一条数据API
  418. deleteOnly (id) {
  419. moduleMgrApi.delete({ id }).then(response => {
  420. const res = response.data
  421. if (res.isSuccess) {
  422. this.$message({
  423. message: this.$t("tips.deleteSuccess"),
  424. type: "success"
  425. })
  426. this.search()
  427. // 清理已经删除的数据
  428. this.$refs.table.clearSelection()
  429. }
  430. })
  431. },
  432. updateStatus (ids) {
  433. moduleMgrApi.updateStatus({ 'ids[]': ids }).then(response => {
  434. const res = response.data
  435. if (res.isSuccess) {
  436. this.$message({
  437. message: '禁用成功',
  438. type: "success"
  439. })
  440. this.search()
  441. }
  442. })
  443. },
  444. view (row) {
  445. // 把数据,设置到【查看】弹出组件
  446. this.$refs.view.setTenant(row)
  447. this.tenantViewVisible = true
  448. },
  449. // 【修改】表头上Btn-事件
  450. editOne() {
  451. if (!this.selection.length) {
  452. this.$message({
  453. message: "请至少选择一条数据!",
  454. type: "warning"
  455. })
  456. return
  457. }
  458. if (this.selection.length > 1) {
  459. this.$message({
  460. message: "请只能选择一条数据!",
  461. type: "warning"
  462. })
  463. return
  464. }
  465. console.log("选择的数据:", this.selection[0]);
  466. this.edit(this.selection[0]);
  467. },
  468. edit (row) {
  469. if (row.readonly) {
  470. this.$message({
  471. message: this.$t("tips.systemData"),
  472. type: "warning"
  473. })
  474. return
  475. }
  476. // 把数据,设置到【查看】弹出组件
  477. this.$refs.edit.setTenant(row, this.dicts)
  478. this.$refs.edit.type = "edit"
  479. this.dialog.title = this.$t("common.edit")
  480. this.dialog.isVisible = true
  481. },
  482. fetch (params = {}) {
  483. this.loading = true
  484. if (this.queryParams.timeRange) {
  485. this.queryParams.map.createTime_st = this.queryParams.timeRange[0]
  486. this.queryParams.map.createTime_ed = this.queryParams.timeRange[1]
  487. }
  488. this.queryParams.current = params.current ? params.current : this.queryParams.current
  489. this.queryParams.size = params.size ? params.size : this.queryParams.size
  490. moduleMgrApi.page(this.queryParams).then(response => {
  491. const res = response.data
  492. if (res.isSuccess) {
  493. // 赋值
  494. this.tableData = res.data
  495. this.tableData.records.forEach((item, index) => {
  496. // item.url = 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg';
  497. item.srcList = [item.pic];
  498. })
  499. }
  500. // eslint-disable-next-line no-return-assign
  501. }).finally(() => this.loading = false)
  502. },
  503. sortChange (val) {
  504. this.queryParams.sort = val.prop
  505. this.queryParams.order = val.order
  506. if (this.queryParams.sort) {
  507. this.search()
  508. }
  509. },
  510. filterChange (filters) {
  511. for (const key in filters) {
  512. if (key.includes('.')) {
  513. const val = {}
  514. val[key.split('.')[1]] = filters[key][0]
  515. this.queryParams.model[key.split('.')[0]] = val
  516. } else {
  517. this.queryParams.model[key] = filters[key][0]
  518. }
  519. }
  520. this.search()
  521. },
  522. cellClick (row, column) {
  523. if (column['columnKey'] === "operation") {
  524. return
  525. }
  526. let flag = false
  527. this.selection.forEach((item) => {
  528. if (item.id === row.id) {
  529. flag = true
  530. this.$refs.table.toggleRowSelection(row)
  531. }
  532. })
  533. if (!flag) {
  534. this.$refs.table.toggleRowSelection(row, true)
  535. }
  536. }
  537. }
  538. }
  539. </script>
  540. <style>
  541. .rearchItem{
  542. margin-left: 15px;
  543. }
  544. </style>
  545. <style lang="scss" scoped>
  546. </style>