123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <template>
- <div class="view-table-content">
- <div style="width: 100%">
- <div class="view-dataType-title">
- <div class="view-dataType-title-btn">
- <el-button type="success" @click="openDialog()">新增</el-button>
- <el-button type="warning" @click="reset()">重置</el-button>
- </div>
- <div class="view-dataType-title-search">
- <el-input placeholder="请输入实体名称" v-model="keyWordData" class="input1">
- <el-button slot="append" icon="el-icon-search" @click="searchClick"></el-button>
- </el-input>
- </div>
- </div>
- <div class="view-dataType-table">
- <LTable ref="table" @selection-change="selection" :defaultFetch="false" :fetch="fetch" :columns="columns" :dataSource="tableData" :options="options"></LTable>
- </div>
- <!-- 添加或修改模型信息对话框 -->
- <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
- <el-form ref="form" :model="form" label-width="80px">
- <el-form-item label="实体名称" prop="name">
- <el-input v-model="form.name" placeholder="请输入实体名称" />
- </el-form-item>
- <el-form-item label="实体类型" prop="category">
- <el-select v-model="form.category" placeholder="请选择实体类型">
- <el-option v-for="(item, index) in categoryList" :key="index" :label="item.name" :value="item.name" />
- </el-select>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="handleClose">取 消</el-button>
- <el-button type="primary" @click="submit">确 定</el-button>
- </span>
- </el-dialog>
- </div>
- </div>
- </template>
- <script>
- import { getEntityList, getAllEntityClass, addEntity, updateEntity, deleteEntity, checkEntity } from '@/api/als/entityManage'
- import { deepClone, debounce } from '@/utils/index'
- export default {
- name: 'AtlasFile',
- components: {},
- data() {
- // 这里存放数据
- return {
- dialogTitle: '新增',
- dialogVisible: false,
- keyWordData: '',
- searchValue: '',
- columns: [
- {
- prop: 'name',
- label: '实体名称'
- },
- {
- prop: 'category',
- label: '实体类型'
- },
- {
- button: true,
- label: '操作',
- width: '240px',
- group: [
- {
- name: '编辑',
- type: 'text',
- round: false,
- plain: false,
- onClick: (row, index, scope) => {
- this.handUpdate(row)
- }
- },
- {
- name: '删除',
- type: 'text',
- round: false,
- plain: false,
- onClick: (row, index, scope) => {
- this.remove([row])
- }
- }
- ]
- }
- ],
- options: {
- stripe: true, // 斑马纹
- mutiSelect: true, // 多选框
- index: false, // 显示序号, 多选则 mutiSelect
- loading: false, // 表格动画
- initTable: false, // 是否一挂载就加载数据
- border: true,
- height: 'calc(100vh - 300px)'
- },
- tableCheckItems: [],
- tableData: [],
- tableRequset: {
- total: 0,
- pageIndex: 1,
- pageSize: 10,
- searchValue: ''
- },
- form: {
- id: '',
- name: '',
- category: ''
- },
- debounceFn: debounce(this.fetch, 500),
- categoryList: []
- }
- },
- watch: {
- keyWord() {
- this.tableRequset.pageIndex = 1
- this.debounceFn()
- }
- },
- mounted() {
- this.getEntityAPI()
- this.getEntityClassAPI()
- },
- methods: {
- async deleteEntityAPI(params) {
- try {
- const deleteData = {
- node_id: params[0]
- }
- const { code } = await deleteEntity(deleteData)
- if (code === 200) {
- this.$message({
- type: 'success',
- message: '操作成功!'
- })
- this.getEntityAPI()
- this.handleClose()
- }
- } catch (error) {}
- },
- reset() {
- this.getEntityAPI()
- this.keyWordData = ''
- },
- async getEntityAPI(params) {
- try {
- if (this.$refs.table) this.$refs.table.clearSelection()
- const {
- data: { dataList, total }
- } = await getEntityList()
- this.tableData = dataList
- this.tableRequset.total = total
- } catch (error) {}
- },
- async getEntityClassAPI(params) {
- try {
- const {
- data: { dataList }
- } = await getAllEntityClass()
- this.categoryList = dataList
- } catch (error) {}
- },
- fetch() {
- this.getEntityAPI()
- },
- async searchClick() {
- try {
- if (this.$refs.table) this.$refs.table.clearSelection()
- const {
- data: { dataList, total }
- } = await checkEntity({ node_name: this.keyWordData })
- this.tableData = dataList
- this.tableRequset.total = total
- } catch (error) {}
- },
- async addEntityAPI() {
- try {
- const addData = {
- node_name: this.form.name,
- node_label: this.form.category
- }
- const { code } = await addEntity(addData)
- if (code === 200) {
- this.$message({
- type: 'success',
- message: '操作成功!'
- })
- this.handleClose()
- this.getEntityAPI()
- }
- } catch (error) {}
- },
- async updateEntityAPI() {
- try {
- const updateData = {
- node_id: this.form.id,
- new_node_name: this.form.name,
- new_node_label: this.form.category
- }
- const { code } = await updateEntity(updateData)
- if (code === 200) {
- this.$message({
- type: 'success',
- message: '操作成功!'
- })
- this.handleClose()
- this.getEntityAPI()
- }
- } catch (error) {}
- },
- openDialog() {
- this.dialogTitle = '新增'
- this.dialogVisible = true
- },
- handleClose() {
- this.dialogVisible = false
- this.form = {
- id: '',
- name: '',
- category: ''
- }
- },
- handUpdate(row) {
- this.dialogTitle = '编辑'
- this.form = deepClone(row)
- this.dialogVisible = true
- },
- submit() {
- switch (this.dialogTitle) {
- case '编辑':
- this.updateEntityAPI()
- break
- case '新增':
- this.addEntityAPI()
- break
- }
- },
- selection(val) {
- this.tableCheckItems = val
- },
- remove(row) {
- this.$confirm('是否删除该数据', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(() => {
- this.deleteEntityAPI(row.map((e) => e.id))
- })
- .catch(() => {})
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import '../../index.scss';
- </style>
|