index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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="reset()">重置</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"></LTable>
  17. </div>
  18. <!-- 添加或修改模型信息对话框 -->
  19. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
  20. <el-form ref="form" :model="form" 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="category">
  25. <el-select v-model="form.category" placeholder="请选择实体类型">
  26. <el-option v-for="(item, index) in categoryList" :key="index" :label="item.name" :value="item.name" />
  27. </el-select>
  28. </el-form-item>
  29. </el-form>
  30. <span slot="footer" class="dialog-footer">
  31. <el-button @click="handleClose">取 消</el-button>
  32. <el-button type="primary" @click="submit">确 定</el-button>
  33. </span>
  34. </el-dialog>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. import { getEntityList, getAllEntityClass, addEntity, updateEntity, deleteEntity, checkEntity } from '@/api/als/entityManage'
  40. import { deepClone, debounce } from '@/utils/index'
  41. export default {
  42. name: 'AtlasFile',
  43. components: {},
  44. data() {
  45. // 这里存放数据
  46. return {
  47. dialogTitle: '新增',
  48. dialogVisible: false,
  49. keyWordData: '',
  50. searchValue: '',
  51. columns: [
  52. {
  53. prop: 'name',
  54. label: '实体名称'
  55. },
  56. {
  57. prop: 'category',
  58. label: '实体类型'
  59. },
  60. {
  61. button: true,
  62. label: '操作',
  63. width: '240px',
  64. group: [
  65. {
  66. name: '编辑',
  67. type: 'text',
  68. round: false,
  69. plain: false,
  70. onClick: (row, index, scope) => {
  71. this.handUpdate(row)
  72. }
  73. },
  74. {
  75. name: '删除',
  76. type: 'text',
  77. round: false,
  78. plain: false,
  79. onClick: (row, index, scope) => {
  80. this.remove([row])
  81. }
  82. }
  83. ]
  84. }
  85. ],
  86. options: {
  87. stripe: true, // 斑马纹
  88. mutiSelect: true, // 多选框
  89. index: false, // 显示序号, 多选则 mutiSelect
  90. loading: false, // 表格动画
  91. initTable: false, // 是否一挂载就加载数据
  92. border: true,
  93. height: 'calc(100vh - 300px)'
  94. },
  95. tableCheckItems: [],
  96. tableData: [],
  97. tableRequset: {
  98. total: 0,
  99. pageIndex: 1,
  100. pageSize: 10,
  101. searchValue: ''
  102. },
  103. form: {
  104. id: '',
  105. name: '',
  106. category: ''
  107. },
  108. debounceFn: debounce(this.fetch, 500),
  109. categoryList: []
  110. }
  111. },
  112. watch: {
  113. keyWord() {
  114. this.tableRequset.pageIndex = 1
  115. this.debounceFn()
  116. }
  117. },
  118. mounted() {
  119. this.getEntityAPI()
  120. this.getEntityClassAPI()
  121. },
  122. methods: {
  123. async deleteEntityAPI(params) {
  124. try {
  125. const deleteData = {
  126. node_id: params[0]
  127. }
  128. const { code } = await deleteEntity(deleteData)
  129. if (code === 200) {
  130. this.$message({
  131. type: 'success',
  132. message: '操作成功!'
  133. })
  134. this.getEntityAPI()
  135. this.handleClose()
  136. }
  137. } catch (error) {}
  138. },
  139. reset() {
  140. this.getEntityAPI()
  141. this.keyWordData = ''
  142. },
  143. async getEntityAPI(params) {
  144. try {
  145. if (this.$refs.table) this.$refs.table.clearSelection()
  146. const {
  147. data: { dataList, total }
  148. } = await getEntityList()
  149. this.tableData = dataList
  150. this.tableRequset.total = total
  151. } catch (error) {}
  152. },
  153. async getEntityClassAPI(params) {
  154. try {
  155. const {
  156. data: { dataList }
  157. } = await getAllEntityClass()
  158. this.categoryList = dataList
  159. } catch (error) {}
  160. },
  161. fetch() {
  162. this.getEntityAPI()
  163. },
  164. async searchClick() {
  165. try {
  166. if (this.$refs.table) this.$refs.table.clearSelection()
  167. const {
  168. data: { dataList, total }
  169. } = await checkEntity({ node_name: this.keyWordData })
  170. this.tableData = dataList
  171. this.tableRequset.total = total
  172. } catch (error) {}
  173. },
  174. async addEntityAPI() {
  175. try {
  176. const addData = {
  177. node_name: this.form.name,
  178. node_label: this.form.category
  179. }
  180. const { code } = await addEntity(addData)
  181. if (code === 200) {
  182. this.$message({
  183. type: 'success',
  184. message: '操作成功!'
  185. })
  186. this.handleClose()
  187. this.getEntityAPI()
  188. }
  189. } catch (error) {}
  190. },
  191. async updateEntityAPI() {
  192. try {
  193. const updateData = {
  194. node_id: this.form.id,
  195. new_node_name: this.form.name,
  196. new_node_label: this.form.category
  197. }
  198. const { code } = await updateEntity(updateData)
  199. if (code === 200) {
  200. this.$message({
  201. type: 'success',
  202. message: '操作成功!'
  203. })
  204. this.handleClose()
  205. this.getEntityAPI()
  206. }
  207. } catch (error) {}
  208. },
  209. openDialog() {
  210. this.dialogTitle = '新增'
  211. this.dialogVisible = true
  212. },
  213. handleClose() {
  214. this.dialogVisible = false
  215. this.form = {
  216. id: '',
  217. name: '',
  218. category: ''
  219. }
  220. },
  221. handUpdate(row) {
  222. this.dialogTitle = '编辑'
  223. this.form = deepClone(row)
  224. this.dialogVisible = true
  225. },
  226. submit() {
  227. switch (this.dialogTitle) {
  228. case '编辑':
  229. this.updateEntityAPI()
  230. break
  231. case '新增':
  232. this.addEntityAPI()
  233. break
  234. }
  235. },
  236. selection(val) {
  237. this.tableCheckItems = val
  238. },
  239. remove(row) {
  240. this.$confirm('是否删除该数据', '提示', {
  241. confirmButtonText: '确定',
  242. cancelButtonText: '取消',
  243. type: 'warning'
  244. })
  245. .then(() => {
  246. this.deleteEntityAPI(row.map((e) => e.id))
  247. })
  248. .catch(() => {})
  249. }
  250. }
  251. }
  252. </script>
  253. <style lang="scss" scoped>
  254. @import '../../index.scss';
  255. </style>