浏览代码

update equipment drawer的逻辑

pull/18/head
lb 1年前
父节点
当前提交
54d22292c1
共有 5 个文件被更改,包括 162 次插入39 次删除
  1. +3
    -2
      .env.dev
  2. +1
    -1
      src/components/DialogForm/index.vue
  3. +6
    -0
      src/mixins/lb/basicPageMixin.js
  4. +119
    -19
      src/views/core/base/equipment/components/EquipmentDrawer.vue
  5. +33
    -17
      src/views/core/base/equipment/index.vue

+ 3
- 2
.env.dev 查看文件

@@ -5,8 +5,9 @@ ENV = 'development'
VUE_APP_TITLE = 芋道管理系统 VUE_APP_TITLE = 芋道管理系统


# 芋道管理系统/开发环境 # 芋道管理系统/开发环境
VUE_APP_BASE_API = 'http://192.168.1.49:48080'
# VUE_APP_BASE_API = 'http://192.168.0.33:48080'
# VUE_APP_BASE_API = 'http://192.168.1.49:48080'
# VUE_APP_BASE_API = 'http://192.168.1.8:48080'
VUE_APP_BASE_API = 'http://192.168.0.33:48080'
# VUE_APP_BASE_API = 'http://192.168.1.188:48080' # VUE_APP_BASE_API = 'http://192.168.1.188:48080'


# 路由懒加载 # 路由懒加载


+ 1
- 1
src/components/DialogForm/index.vue 查看文件

@@ -53,7 +53,7 @@
:action="col.url" :action="col.url"
:on-success="handleUploadSuccess" :on-success="handleUploadSuccess"
v-bind="col.bind"> v-bind="col.bind">
<el-button size="small" type="primary">点击上传</el-button>
<el-button size="small" type="primary" :disabled="col.bind?.disabled || false">点击上传</el-button>
<div class="el-upload__tip" slot="tip" v-if="col.uploadTips"> <div class="el-upload__tip" slot="tip" v-if="col.uploadTips">
{{ col.uploadTips || '只能上传jpg/png文件,大小不超过2MB' }} {{ col.uploadTips || '只能上传jpg/png文件,大小不超过2MB' }}
</div> </div>


+ 6
- 0
src/mixins/lb/basicPageMixin.js 查看文件

@@ -87,6 +87,12 @@ export default {
}, },
handleEmitFun(val) { handleEmitFun(val) {
console.log('emit unf', val); console.log('emit unf', val);
switch (val.action) {
// 查看详情
case 'show-detail':
this.viewDetail(val.value); // 交由每个组件自己实现
break;
}
}, },
// 获取列表数据 // 获取列表数据
getList() {}, getList() {},


+ 119
- 19
src/views/core/base/equipment/components/EquipmentDrawer.vue 查看文件

@@ -35,11 +35,12 @@
v-if="showForm" v-if="showForm"
ref="form" ref="form"
:dataForm="form" :dataForm="form"
:rows="section.rows" />
:rows="formRows" />
</div> </div>


<div v-if="section.key == 'attrs'" style="margin-top: 12px"> <div v-if="section.key == 'attrs'" style="margin-top: 12px">
<base-table <base-table
v-loading="attrListLoading"
:table-props="section.props" :table-props="section.props"
:page="section.pageNo || 1" :page="section.pageNo || 1"
:limit="section.pageSize || 10" :limit="section.pageSize || 10"
@@ -49,7 +50,7 @@
v-if="section.tableBtn" v-if="section.tableBtn"
slot="handleBtn" slot="handleBtn"
label="操作" label="操作"
:method-list="section.tableBtn"
:method-list="tableBtn"
@clickBtn="handleTableBtnClick" /> @clickBtn="handleTableBtnClick" />
</base-table> </base-table>
</div> </div>
@@ -126,7 +127,7 @@ const SmallTitle = {


export default { export default {
components: { SmallTitle, DialogForm }, components: { SmallTitle, DialogForm },
props: ['sections', 'mode'],
props: ['sections', 'mode', 'dataId'], // dataId 作为一个通用的存放id的字段
data() { data() {
return { return {
visible: false, visible: false,
@@ -159,23 +160,46 @@ export default {
}, },
], ],
], ],
attrQuery: null, // 属性列表的请求
infoQuery: null, // 基本信息的请求
attrFormSubmitting: false,
attrListLoading: false
}; };
}, },
computed: {
formRows() {
return this.sections[0].rows.map((row) => {
return row.map((col) => ({
...col,
bind: {
// 详情 模式下,禁用各种输入
disabled: this.mode == 'detail',
},
}));
});
},
tableBtn() {
return this.mode == 'detail' ? [] : this.sections[1].tableBtn;
},
},
mounted() { mounted() {
for (const section of this.sections) { for (const section of this.sections) {
// 请求具体信息 // 请求具体信息
if ('url' in section) { if ('url' in section) {
this.$axios({
const query = {
url: section.url, url: section.url,
method: section.method || 'get', method: section.method || 'get',
params: section.queryParams || null, params: section.queryParams || null,
data: section.data || null, data: section.data || null,
}).then(({ data }) => {
};
this.$axios(query).then(({ data }) => {
if (section.key == 'base') { if (section.key == 'base') {
this.form = data; this.form = data;
this.showForm = true; this.showForm = true;
this.infoQuery = query;
console.log('setting form: ', this.form, data); console.log('setting form: ', this.form, data);
} else if (section.key == 'attrs') { } else if (section.key == 'attrs') {
this.attrQuery = query;
this.list = data.list; this.list = data.list;
this.total = data.total; this.total = data.total;
} }
@@ -184,14 +208,35 @@ export default {
} }
}, },
methods: { methods: {
handleTableBtnClick() {},
handleTableBtnClick({ type, data }) {
switch (type) {
case 'edit':
this.handleEditAttr(data.id);
break;
case 'delete':
this.handleDeleteAttr(data.id);
break;
}
},


handleEmitFun() {},
handleEmitFun(val) {
console.log('handleEmitFun', val);
},


init() { init() {
this.visible = true; this.visible = true;
}, },


async getAttrList() {
this.attrListLoading = true;
const res = await this.$axios(this.attrQuery);
if (res.code == 0) {
this.list = data.list;
this.total = data.total;
}
this.attrListLoading = false;
},

// 保存表单 // 保存表单
handleSave() { handleSave() {
this.$refs['form'][0].validate(async (valid) => { this.$refs['form'][0].validate(async (valid) => {
@@ -218,11 +263,12 @@ export default {
this.mode = 'edit'; this.mode = 'edit';
}, },


// 开启属性编辑/新增
// 新增属性
handleAddAttr() { handleAddAttr() {
if (!this.dataId) return this.$message.error('请先创建设备信息');
this.attrForm = { this.attrForm = {
id: null, id: null,
equipmentId: null,
equipmentId: this.dataId,
name: '', name: '',
value: '', value: '',
}; };
@@ -230,13 +276,75 @@ export default {
this.attrFormVisible = true; this.attrFormVisible = true;
}, },


// 编辑属性
async handleEditAttr(attrId) {
const res = await this.$axios({
url: this.sections[1].urlDetail,
method: 'get',
params: { id: attrId },
});
if (res.code == 0) {
this.attrForm = res.data;
this.attrTitle = '编辑设备属性';
this.attrFormVisible = true;
}
},

// 删除属性
handleDeleteAttr(attrId) {
this.$confirm('确定删除该属性?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(async () => {
const res = await this.$axios({
url: this.sections[1].urlDelete,
method: 'delete',
params: { id: attrId },
});
if (res.code == 0) {
this.$message({
message: '删除成功',
type: 'success',
duration: 1500,
onClose: () => {
this.getAttrList();
},
});
}
})
.catch(() => {});
},

// 提交属性表 // 提交属性表
submitAttrForm() {
this.$refs['form'].validate((valid) => {
async submitAttrForm() {
this.$refs['attrForm'].validate((valid) => {
if (!valid) { if (!valid) {
return; return;
} }
}); });
console.log('this.attrform', this.attrForm);
const isEdit = this.attrForm.id != null;
this.attrFormSubmitting = true;
const res = await this.$axios({
url: isEdit ? this.sections[1].urlUpdate : this.sections[1].urlCreate,
method: isEdit ? 'put' : 'post',
data: this.attrForm,
});
if (res.code == 0) {
this.closeAttrForm();
this.$message({
message: `${isEdit ? '更新' : '创建'}成功`,
type: 'success',
duration: 1500,
onClose: () => {
this.getAttrList();
},
});
}
this.attrFormSubmitting = false;
}, },


closeAttrForm() { closeAttrForm() {
@@ -275,14 +383,6 @@ export default {
this.addNew(raw.data.id); this.addNew(raw.data.id);
} }
}, },

// 新增 / 修改
addNew(id) {
this.addOrUpdateVisible = true;
this.$nextTick(() => {
this.$refs.addOrUpdate.init(id);
});
},
}, },
}; };
</script> </script>


+ 33
- 17
src/views/core/base/equipment/index.vue 查看文件

@@ -44,6 +44,7 @@
v-if="editVisible" v-if="editVisible"
ref="drawer" ref="drawer"
:mode="editMode" :mode="editMode"
:data-id="form.id"
:sections="[ :sections="[
{ {
name: '基本信息', name: '基本信息',
@@ -59,15 +60,29 @@
key: 'attrs', key: 'attrs',
props: drawerListProps, props: drawerListProps,
url: '/base/equipment-attr/page', url: '/base/equipment-attr/page',
urlCreate: '/base/equipment-attr/create',
urlUpdate: '/base/equipment-attr/update',
urlDelete: '/base/equipment-attr/delete',
urlDetail: '/base/equipment-attr/get',
queryParams: { queryParams: {
equipmentId: form.id, equipmentId: form.id,
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
}, },
tableBtns: [
{ name: 'edit', url: '', permission: '' },
{ name: 'delete', url: '', permission: '' },
],
tableBtn: [
this.$auth.hasPermi('base:equipment-attr:update')
? {
type: 'edit',
btnName: '修改',
}
: undefined,
this.$auth.hasPermi('base:equipment-attr:delete')
? {
type: 'delete',
btnName: '删除',
}
: undefined,
].filter((v) => v),
allowAdd: true, allowAdd: true,
}, },
]" ]"
@@ -130,7 +145,6 @@ export default {
{ prop: 'name', label: '设备名称', align: 'center' }, { prop: 'name', label: '设备名称', align: 'center' },
{ prop: 'code', label: '检测编码', align: 'center' }, { prop: 'code', label: '检测编码', align: 'center' },
{ prop: 'equipmentType', label: '设备类型', align: 'center' }, { prop: 'equipmentType', label: '设备类型', align: 'center' },
{ prop: 'equipmentGroup', label: '设备分组', align: 'center' },
{ prop: 'enName', label: '英文名称', align: 'center' }, { prop: 'enName', label: '英文名称', align: 'center' },
{ prop: 'abbr', label: '缩写', align: 'center' }, { prop: 'abbr', label: '缩写', align: 'center' },
{ {
@@ -205,7 +219,7 @@ export default {
prop: 'name', prop: 'name',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }], rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
// bind: { // bind: {
// disabled: true, // some condition, like detail mode...
// disabled: this.editMode == 'detail', // some condition, like detail mode...
// } // }
}, },
{ {
@@ -359,8 +373,8 @@ export default {
width: 180, width: 180,
filter: (val) => moment(val).format('yyyy-MM-DD HH:mm:ss'), filter: (val) => moment(val).format('yyyy-MM-DD HH:mm:ss'),
}, },
{ prop: 'keyName', label: '属性名称', align: 'center' },
{ prop: 'keyValue', label: '属性值', align: 'center' },
{ prop: 'name', label: '属性名称', align: 'center' },
{ prop: 'value', label: '属性值', align: 'center' },
], ],
// 是否显示弹出层 // 是否显示弹出层
open: false, open: false,
@@ -498,7 +512,17 @@ export default {
}) })
.catch(() => {}); .catch(() => {});
}, },
// 重写 basicPageMixin 里的 处理表格按钮 方法
// 查看详情
viewDetail(id) {
this.reset();
this.editMode = 'detail';
this.form.id = id;
this.editVisible = true;
this.$nextTick(() => {
this.$refs['drawer'].init();
});
},
// overwrite basicPageMixin 里的 处理表格按钮 方法
handleTableBtnClick({ data, type }) { handleTableBtnClick({ data, type }) {
console.log('[handleTableBtnClick]', data, type); console.log('[handleTableBtnClick]', data, type);
switch (type) { switch (type) {
@@ -510,14 +534,6 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['drawer'].init(); this.$refs['drawer'].init();
}); });

// getEquipment(id).then((response) => {
// this.form = response.data;
// this.editVisible = true;
// this.$nextTick(() => {
// this.$refs['drawer'].init();
// });
// });
break; break;
case 'delete': case 'delete':
this.handleDelete(data); this.handleDelete(data);


正在加载...
取消
保存