Compare commits

...

7 Commits

11 changed files with 1164 additions and 40 deletions

31
package-lock.json generated
View File

@ -7120,6 +7120,22 @@
"safer-buffer": "^2.1.0"
}
},
"echarts": {
"version": "5.3.3",
"resolved": "https://registry.npmjs.org/echarts/-/echarts-5.3.3.tgz",
"integrity": "sha512-BRw2serInRwO5SIwRviZ6Xgm5Lb7irgz+sLiFMmy/HOaf4SQ+7oYqxKzRHAKp4xHQ05AuHw1xvoQWJjDQq/FGw==",
"requires": {
"tslib": "2.3.0",
"zrender": "5.3.2"
},
"dependencies": {
"tslib": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz",
"integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="
}
}
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npm.taobao.org/ee-first/download/ee-first-1.1.1.tgz",
@ -17269,6 +17285,21 @@
"integrity": "sha1-48mzFWnhBoEd8kL3FXJaH0xJQyA="
}
}
},
"zrender": {
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/zrender/-/zrender-5.3.2.tgz",
"integrity": "sha512-8IiYdfwHj2rx0UeIGZGGU4WEVSDEdeVCaIg/fomejg1Xu6OifAL1GVzIPHg2D+MyUkbNgPWji90t0a8IDk+39w==",
"requires": {
"tslib": "2.3.0"
},
"dependencies": {
"tslib": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz",
"integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="
}
}
}
}
}

View File

@ -15,6 +15,7 @@
"babel-plugin-component": "^1.1.1",
"ckeditor4-vue": "^2.1.1",
"core-js": "^3.6.5",
"echarts": "^5.3.3",
"element-theme": "^2.0.1",
"element-ui": "^2.15.7",
"js-cookie": "^2.2.1",

View File

@ -0,0 +1,548 @@
<template>
<div class="super-flexible-dialog" :title="isDetail ? title.detail : !dataForm.id ? title.add : title.edit" @close="handleClose">
<div style="max-height: 60vh; overflow-y: scroll; overflow-x: hidden;">
<el-form ref="dataForm" :model="dataForm" :rules="dataFormRules">
<!-- 如果需要更精细一点的布局可以根据配置项实现地再复杂一点但此处暂时全部采用一行两列布局 -->
<el-row v-for="n in rows" :key="n" :gutter="20">
<el-col v-for="c in COLUMN_PER_ROW" :key="`${n}+'col'+${c}`" :span="getSpan(n, c)">
<!-- <el-col v-for="c in COLUMN_PER_ROW" :key="`${n}+'col'+${c}`" :span="24 / COLUMN_PER_ROW"> -->
<!-- :class="{ 'hidden-input': configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].hidden }" -->
<el-form-item
v-if="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)]"
:prop="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name"
:key="`${n}-col-${c}-item`"
:label="getLabel(n, c)"
>
<!-- 暂时先不实现部分输入方式 -->
<el-input
v-if="getType(n, c) === 'input'"
:placeholder="getPlaceholder(n, c)"
v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
clearable
/>
<el-radio v-if="getType(n, c) === 'radio'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-radio>
<el-checkbox v-if="getType(n, c) === 'check'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-checkbox>
<el-select
v-if="getType(n, c) === 'select'"
:placeholder="getPlaceholder(n, c)"
v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
clearable
@change="emitSelectChange(configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name, $event)"
>
<el-option v-for="opt in configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].options" :key="opt.label" :label="opt.label" :value="opt.value" />
</el-select>
<el-switch v-if="getType(n, c) === 'switch'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-switch>
<el-cascader
v-if="getType(n, c) === 'cascader'"
v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
:options="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].options"
:props="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].props"
></el-cascader>
<el-time-select v-if="getType(n, c) === 'time'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-time-select>
<el-date-picker
v-if="getType(n, c) === 'date'"
v-bind="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].props"
:placeholder="getPlaceholder(n, c)"
v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
></el-date-picker>
</el-form-item>
</el-col>
</el-row>
<!-- extra components , like Markdown or RichEdit -->
<template v-if="configs.extraComponents && configs.extraComponents.length > 0">
<el-form-item v-for="(ec, index) in configs.extraComponents" :key="ec.name + index" :label="ec.label" class="extra-components">
<component style="margin-top: 40px;" v-if="ec.hasModel" :is="ec.component" v-bind="ec.props" v-model="dataForm[ec.name]" @ready="handleEditorReady" />
<!-- <component v-if="ec.hasModel" :is="ec.component" v-bind="ec.props" v-model="dataForm[ec.name]" /> -->
<component
v-else
:is="ec.component"
v-bind="ec.props"
@uploader-update-filelist="handleUploadListUpdate($event, ec.props.extraParams.typeCode)"
:uploader-inject-file-list="/*用于设备分流的*/ fileList[ec.props.extraParams.typeCode]"
/>
</el-form-item>
</template>
</el-form>
<template v-if="dataForm.id && configs.subtable">
<attr-form :pId="dataForm.id" v-bind="configs.subtable" />
</template>
</div>
<span slot="footer" class="dialog-footer">
<template v-for="(operate, index) in configs.operations">
<!-- {{ operate.name | btnNameFilter }} -->
<el-button
v-if="
operate.showAlways ||
(((dataForm.id && operate.showOnEdit) || (!dataForm.id && !operate.showOnEdit)) && (operate.permission ? $hasPermission(operate.permission) : true))
"
:key="`operate-${index}`"
:type="btnType[operate.name]"
@click="handleClick(operate)"
>{{ btnName[operate.name] }}</el-button
>
</template>
</span>
</div>
</template>
<script>
import AttrForm from '../AttrForm'
import { pick } from 'lodash/object'
// for i18n
const title = {
detail: '详情',
add: '新增',
edit: '编辑'
}
//
const btnType = {
save: 'success',
update: 'primary',
reset: 'text'
// cancel: 'text'
// add more...
}
const btnName = {
// for i18n
save: '保存',
update: '更新',
reset: '重置',
cancel: '取消'
// add more...
}
//
const COLUMN_PER_ROW = 2
export default {
name: 'AddOrUpdateDialog',
components: { AttrForm },
props: {
configs: {
/**
* TODO: 定义及使用方式应改用README.md文件记录
* type: 'dialog' | 'drawer' | 'page'
* fields: Array<string|object>
* - fields.object: { name, type: 'number'|'textarea'|'select'|'date'|.., required: boolean, validator: boolean(是否需要验证), [options]: any[], api: string(自动获取数据的接口一般为getcode接口)}
* operations: Array[object], 操作名和对应的接口地址还有permission(sys:dict:update)
*/
type: Object,
default: () => ({}) // 使
}
},
filters: {
nameFilter: function(name) {
if (!name) return null
// for i18n
const defaultNames = {
name: '名称',
code: '编码',
remark: '备注',
description: '描述',
specifications: '规格'
// add more...
}
return defaultNames[name]
}
},
// provide() {
// return {
// _df: this.dataForm
// }
// },
data() {
return {
COLUMN_PER_ROW,
title,
/** 按钮相关属性 */
btnName,
btnType,
defaultNames: {
name: '名称',
code: '编码',
remark: '备注',
description: '描述',
specifications: '规格'
// add more...
},
defaultPlaceholders: {}, // defaultNames
/** 表单相关属性 */
visible: false,
isEdit: false,
isDetail: false,
dataForm: {},
dataFormRules: {},
tempForm: [], // code
shouldWait: null,
fileForm: {}, // typeCode
fileList: {} // typeCode
}
},
computed: {
rows() {
// ''
return Math.ceil(this.configs.fields.length / COLUMN_PER_ROW)
}
},
mounted() {
/** 计算 defaultPlaceholders */
const prefix = '请输入'
Object.entries(this.defaultNames).map(([key, value]) => {
this.defaultPlaceholders[key] = prefix + value
})
/** 转换 configs.fields 的结构,把纯字符串转为对象 */
this.$nextTick(() => {
this.configs.fields = this.configs.fields.map(item => {
if (typeof item === 'string') {
return { name: item }
}
return item
})
/** 动态设置dataForm字段 */
this.configs.fields.forEach(item => {
this.$set(this.dataForm, [item.name], '')
/** select 的默认值设置 */
if (item.type === 'select') {
const opts = item.options || []
const dft = opts.find(item => item.default || false)
if (dft) {
this.$set(this.dataForm, [item.name], dft.value)
}
}
if (item.api) {
/** 自动请求并填充 */
// or this.shouldWaitPool = []
this.shouldWait = this.$http({
url: this.$http.adornUrl(item.api),
method: 'POST' //
}).then(({ data: res }) => {
if (res && res.code === 0) {
// this.dataForm[item.name] = res.data // <===
this.tempForm.push({ name: item.name, data: res.data })
}
})
} // end if (item.api)
if (item.required) {
const requiredRule = {
required: true,
message: '请输入必填项',
trigger: 'change'
}
/** 检查是否已经存在该字段的规则 */
const exists = this.dataFormRules[item.name] || null
/** 设置验证规则 */
if (exists) {
const unset = true
for (const rule of exists) {
if (rule.required) unset = false
}
if (unset) {
exists.push(requiredRule)
}
} else {
/** 不存在已有规则 */
this.$set(this.dataFormRules, [item.name], [requiredRule])
}
} // end if (item.required)
if (item.rules) {
const exists = this.dataFormRules[item.name] || null
if (exists) {
//
exists.push(...item.rules)
} else {
this.$set(this.dataFormRules, [item.name], [...item.rules])
}
} // end if (item.rules)
})
/** 计算默认值 */
function calDefault(type) {
switch (type) {
case 'array':
return []
// more case...
default:
return ''
}
}
/** 检查是否需要额外的组件 */
this.configs.extraComponents &&
this.configs.extraComponents.forEach(item => {
if (Object.hasOwn(this.dataForm, [item.name])) {
console.log('有了!')
return
} else {
console.log('新建!')
this.$set(this.dataForm, [item.name], calDefault(item.fieldType))
}
console.log('component: ', item.component)
})
/** 单独设置 id */
this.$set(this.dataForm, 'id', null)
console.log('mounted: this.dataForm', JSON.stringify(this.dataForm))
})
},
methods: {
getSpan(n, c) {
const opt = this.configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)]
return opt && opt.span ? opt.span : 24 / COLUMN_PER_ROW
},
getLabel(n, c) {
const opt = this.configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)]
if (opt) {
// if opt is valid
return opt.label ? opt.label : this.defaultNames[opt.name]
}
},
getPlaceholder(n, c) {
const opt = this.configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)]
if (opt) {
// if opt is valid
return opt.placeholder
? opt.placeholder
: this.defaultPlaceholders[opt.name]
? this.defaultPlaceholders[opt.name]
: opt.label
? (opt.type === 'select' ? '请选择' : '请输入') + opt.label
: null
// : opt.type === 'select'
// ? ''
// : ''
}
},
getType(n, c) {
const opt = this.configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)]
if (opt) {
if (!opt.type || ['input', 'number' /** add more.. */].includes(opt.type)) {
return 'input'
} else if (['select' /** add more.. */].includes(opt.type)) {
return 'select'
} else if (['cascader'].includes(opt.type)) {
return 'cascader'
} else if (['date'].includes(opt.type)) {
return 'date'
}
// add more...
} else {
return 'input'
}
},
init(id) {
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
this.dataForm.id = id || null
if (this.dataForm.id) {
this.$http({
url: this.$http.adornUrl(`${this.configs.infoUrl}/${this.dataForm.id}`),
method: 'get'
}).then(({ data: res }) => {
if (res && res.code === 0) {
const dataFormKeys = Object.keys(this.dataForm)
console.log('data form keys: ', dataFormKeys, pick(res.data, dataFormKeys))
this.dataForm = pick(res.data, dataFormKeys)
// LABEL: FILE_RELATED
/** 对文件下载进行分流 */
this.fileList = {}
if (this.dataForm.files) {
console.log('files: ', this.dataForm.files)
this.dataForm.files.forEach(file => {
// const fileName = file.fileUrl.split('/').pop()
/** [1] 处理 fileList */
if (Object.hasOwn(this.fileList, file.typeCode)) {
/** 已存在 */
// this.fileList[file.typeCode].push({ id: file.id, name: fileName, typeCode: file.typeCode })
this.fileList[file.typeCode].push(file)
} else {
// this.fileList[file.typeCode] = [{ id: file.id, name: fileName, typeCode: file.typeCode }]
this.fileList[file.typeCode] = [file]
}
/** [2] 处理 fileForm */
if (Object.hasOwn(this.fileForm, file.typeCode)) {
this.fileForm[file.typeCode].push(file.id)
} else {
this.fileForm[file.typeCode] = [file.id]
}
})
console.log('after分流', this.fileList)
}
}
})
} else {
/** 如果不是编辑,就填充自动生成的数据 */
if (this.shouldWait)
this.shouldWait.then(() => {
if (this.tempForm.length) {
console.log('create new, tempform', JSON.stringify(this.tempForm.length))
this.tempForm.forEach(item => {
console.log('item data', item.data)
this.dataForm[item.name] = item.data
})
console.log('create new, dataform', JSON.stringify(this.dataForm))
}
})
}
})
},
emitSelectChange(name, id) {
this.$emit('select-change', { name, id })
},
handleEditorReady(val) {
console.log('editor rready..', val)
},
handleClick(btn) {
/** 提取url */
const urls = {}
this.configs.operations.map(item => {
urls[item.name] = {}
urls[item.name].url = item.url
urls[item.name].extraFields = item.extraFields || {}
})
/** 操作 */
switch (btn.name) {
case 'save':
case 'update':
/** 需要验证表单的操作 */
this.$refs['dataForm'].validate(valid => {
if (valid) {
/** 对于文件上传的单独处理(合并处理) */
if (Object.keys(this.fileForm).length) {
console.log('fileform 有值')
// LABEL: FILE_RELATED
let fileIds = []
for (const [key, item] of Object.entries(this.fileForm)) {
if (Array.isArray(item)) {
fileIds = fileIds.concat(item)
} else {
console.error('handleClick(): 上传文件数组类型不正确')
}
}
this.$set(this.dataForm, 'fileIds', fileIds)
}
console.log('before send: ', this.dataForm)
this.$http({
url: this.$http.adornUrl(urls[btn.name].url),
method: btn.name === 'save' ? 'POST' : 'PUT',
data: { ...this.dataForm, ...urls[btn.name].extraFields }
})
.then(({ data: res }) => {
if (res && res.code === 0) {
this.$message({
message: btn.name === 'save' ? '添加成功!' : '更新成功!',
type: 'success',
duration: 1500,
onClose: () => {
this.$emit('refreshDataList')
this.visible = false
}
})
} else {
this.$message.error(res.msg)
}
})
.catch(err => {
this.$message({
message: err,
type: 'error',
duration: 2000
})
})
}
})
return
case 'reset':
for (const key of Object.keys(this.dataForm)) {
if (typeof this.dataForm[key] === 'string') {
this.dataForm[key] = ''
} else if (this.dataForm[key] instanceof Array) {
this.dataForm[key].splice(0)
} else {
this.dataForm[key] = null
}
}
break
case 'cancel':
this.visible = false
// add more..
}
},
// LABEL: FILE_RELATED
handleUploadListUpdate(filelist, typeCode = 'DefaultTypeCode') {
console.log('before handleUploadListUpdate(): ', JSON.parse(JSON.stringify(this.fileForm)))
// typeCode: EquipmentTypeFile
// typeCode: EquipmentInfoFile | EquipmentInfoImage
// dataForm
// this.$set(
// this.dataForm,
// 'fileIds',
// filelist.map(item => item.id)
// )
// console.log('handleUploadListUpdate(): ', this.dataForm)
//
this.$set(
this.fileForm,
typeCode,
filelist.map(item => item.id)
)
console.log('after handleUploadListUpdate(): ', this.fileForm)
},
handleClose() {
this.$emit('destory-dialog')
this.visible = false
}
}
}
</script>
<style scoped>
.super-flexible-dialog >>> .el-select,
.super-flexible-dialog >>> .el-cascader {
width: 100%;
}
.super-flexible-dialog >>> ::-webkit-scrollbar {
width: 4px;
border-radius: 4px;
background: #fff;
}
.super-flexible-dialog >>> ::-webkit-scrollbar-thumb {
width: 4px;
border-radius: 4px;
background: #ccc;
}
.super-flexible-dialog >>> .hidden-input {
display: none;
}
</style>

View File

@ -66,8 +66,14 @@ export default {
default: () => []
},
/** 表单提交需要的属性 */
pId: {
relatedId: {
type: String,
required: true,
default: null
},
relatedField: {
type: String,
required: true,
default: null
}
},
@ -96,12 +102,12 @@ export default {
},
mounted() {
this.getDataList()
/** 设置 AttrForm 的 rules */
for(const config of this.tableConfigs) {
if (config.rules) {
this.$set(this.AttrFormRules, [config.prop], config.rules)
}
}
/** 设置 AttrForm 的 rules */
for (const config of this.tableConfigs) {
if (config.rules) {
this.$set(this.AttrFormRules, [config.prop], config.rules)
}
}
},
methods: {
/** init dataform */
@ -127,7 +133,7 @@ export default {
params: this.$http.adornParams({
page: this.pageIndex,
limit: this.pageSize,
productId: this.pId
[this.relatedField]: this.relatedId
// order: 'asc/desc',
// orderField: 'name'
})
@ -210,7 +216,7 @@ export default {
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify({ ...this.AttrForm, productId: this.pId })
data: JSON.stringify({ ...this.AttrForm, [this.relatedField]: this.relatedId })
}).then(({ data }) => {
if (data && data.code === 0) {
this.$message({

View File

@ -27,6 +27,7 @@
:placeholder="getPlaceholder(n, c)"
v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
clearable
@change="emitSelectChange(configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name, $event)"
>
<el-option v-for="opt in configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].options" :key="opt.label" :label="opt.label" :value="opt.value" />
</el-select>
@ -41,6 +42,7 @@
<el-date-picker
v-if="getType(n, c) === 'date'"
v-bind="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].props"
:placeholder="getPlaceholder(n, c)"
v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
></el-date-picker>
</el-form-item>
@ -64,7 +66,7 @@
</el-form>
<template v-if="dataForm.id && configs.subtable">
<attr-form :pId="dataForm.id" v-bind="configs.subtable" />
<attr-form :related-id="dataForm.id" v-bind="configs.subtable" />
</template>
</div>
<span slot="footer" class="dialog-footer">
@ -207,6 +209,16 @@ export default {
/** 动态设置dataForm字段 */
this.configs.fields.forEach(item => {
this.$set(this.dataForm, [item.name], '')
/** select 的默认值设置 */
if (item.type === 'select') {
const opts = item.options || []
const dft = opts.find(item => item.default || false)
if (dft) {
this.$set(this.dataForm, [item.name], dft.value)
}
}
if (item.api) {
/** 自动请求并填充 */
// or this.shouldWaitPool = []
@ -395,6 +407,10 @@ export default {
})
},
emitSelectChange(name, id) {
this.$emit('select-change', { name, id })
},
handleEditorReady(val) {
console.log('editor rready..', val)
},

View File

@ -0,0 +1,67 @@
<!--
* @Author: lb
* @Date: 2022-05-18 16:00:00
* @LastEditors: lb
* @LastEditTime: 2022-05-18 16:00:00
* @Description:
-->
<template>
<div :class="[className, { 'p-0': noPadding }]">
<slot />
</div>
</template>
<script>
export default {
props: {
size: {
// : xl lg md sm
type: String,
default: 'de',
validator: function(val) {
return ['xl', 'lg', 'de', 'md', 'sm'].indexOf(val) !== -1
}
},
noPadding: {
type: Boolean,
default: false
}
},
computed: {
className: function() {
return `${this.size}-title`
}
}
}
</script>
<style lang="scss" scoped>
$pxls: (xl, 28px) (lg, 24px) (de, 22px) (md, 18px) (sm, 16px);
$mgr: 6px;
@each $size, $height in $pxls {
.#{$size}-title {
padding: 8px 0;
font-size: $height;
line-height: $height;
color: #000;
font-weight: 500;
font-family: '微软雅黑', 'Microsoft YaHei', Arial, Helvetica, sans-serif;
&::before {
content: '';
display: inline-block;
vertical-align: top;
width: 4px;
height: $height + 2px;
border-radius: 1px;
margin-right: $mgr;
// background-color: #0b58ff;
background-color: #409EFF;
}
}
}
.p-0 {
padding: 0;
}
</style>

View File

@ -154,6 +154,18 @@ const addOrUpdateConfigs = {
}
}
],
subtable: {
title: '查看设备属性',
url: '/monitoring/equipmentAttr',
relatedField: 'equipmentId',
tableConfigs: [
{ type: 'index', name: '序号' },
{ prop: 'createTime', name: '创建时间' },
{ prop: 'attrName', name: '属性名称', formField: true },
{ prop: 'attrValue', name: '属性值', formField: true },
{ prop: 'operate', name: '操作', options: ['edit', 'delete'] }
]
},
operations: [
{ name: 'cancel', showAlways: true },
{ name: 'save', url: '/monitoring/equipment', permission: '', showOnEdit: false },

View File

@ -140,6 +140,7 @@ const addOrUpdateConfigs = {
// for i18n
title: '动态属性',
url: '/monitoring/productArrt',
relatedField: 'productId',
tableConfigs: [
{ type: 'index', name: '序号' },
{ prop: 'createTime', name: '添加时间', filter: val => (val ? moment(val).format('YYYY-MM-DD hh:mm:ss') : '-') },

View File

@ -0,0 +1,369 @@
<template>
<div class="mod-config">
<el-form :inline="true" @keyup.enter.native="getDataList()">
<el-form-item>
<!-- type="datetimerange" -->
<el-date-picker
type="daterange"
v-model="datetime"
value-format="yyyy-MM-ddTHH:mm:ss"
start-placeholder="开始时间"
end-placeholder="结束时间"
range-separator="至"
:default-time="['00:00:00', '23:59:59']"
:picker-options="quickOptions"
clearable
/>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()">查询</el-button>
<!-- <el-button v-if="$hasPermission('monitoring:qualityinspectionrecord:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button> -->
</el-form-item>
</el-form>
<div class="quality-inspection-current base-container">
<el-row>
<el-col>
<small-title :size="'md'">上下片及检测总数统计</small-title>
<el-row style="margin-top: 12px;">
<base-table :data="dataListStatic" :table-head-configs="tableConfigStatic" :max-height="500" @operate-event="handleOperations" @refreshDataList="getDataList" />
</el-row>
</el-col>
</el-row>
<el-row style="margin-top: 28px;">
<el-col>
<el-row>
<small-title :size="'md'">各产线检测类型统计</small-title>
</el-row>
<el-row style="margin-top: 8px;">
<el-radio-group v-model="dataType" size="medium" @change="handleDataTypeChange">
<el-radio-button label="表格"></el-radio-button>
<el-radio-button label="图形"></el-radio-button>
</el-radio-group>
</el-row>
<el-row style="margin-top: 12px;">
<base-table
v-if="!showGraph"
:data="dataListDynamic"
:table-head-configs="tableConfigDynamic"
:max-height="500"
@operate-event="handleOperations"
@refreshDataList="getDataList"
/>
<fake-chart v-else :categories="echartCategories" :type-list="echartCheckTypes" :series-data="echartsData" />
</el-row>
</el-col>
</el-row>
</div>
</div>
</template>
<script>
import moment from 'moment'
import BaseTable from '@/components/base-table'
import SmallTitle from '@/components/small-title'
import * as echarts from 'echarts'
const tableConfigStatic = [
{ type: 'index', name: '序号' },
{ name: '上片总数', prop: 'sumUp' },
{ name: '下片总数', prop: 'sumDown' },
{ name: '检测总数', prop: 'sumCheck' },
{ name: '比例', prop: 'scrapRatio', filter: val => (val || val === 0 ? `${val}%` : '-') }
]
const tableConfigDynamic = [
{ type: 'index', name: '序号' },
{ name: '检测类型', prop: 'inspectionContent' },
/** dynamic */
{ name: '检测类型总数', prop: '' },
{ name: '比例', prop: '' }
]
const FakeChart = {
name: 'FakeChart',
props: {
categories: {
type: Array,
default: () => []
},
typeList: {
type: Array,
default: () => []
},
seriesData: {
type: Array,
default: () => []
}
},
data() {
return {
chart: null,
defaultOpts: {
title: {
text: '检测类型统计数据'
},
tooltip: {},
legend: {
orient: 'vertical',
top: 10,
right: 20,
data: [
/** dynamic */
]
},
xAxis: {
data: [
/** dynamic */
]
},
yAxis: {},
series: [
// dynamic
// {
// name: '',
// type: 'bar',
// data: [23, 42, 12, 4, 3]
// }
]
}
}
},
watch: {
categories: {
handler: function(val, oldVal) {
if (val && val !== oldVal) {
this.defaultOpts.xAxis.data.push(...val)
}
},
immediate: true
},
typeList: {
handler: function(val, oldVal) {
if (val && val !== oldVal) {
this.defaultOpts.legend.data.push(...val)
}
},
immediate: true
},
seriesData: {
handler: function(val, oldVal) {
if (val && val !== oldVal) {
this.defaultOpts.series.push(...val)
}
},
immediate: true
},
defaultOpts: {
handler: function(val) {
console.log('defaullt opts change: ', val)
this.setOptions()
},
immediate: true,
deep: true
}
},
mounted() {
this.$nextTick(() => {
this.initChart()
this.setOptions()
})
},
methods: {
initChart() {
if (!this.chart) {
this.chart = echarts.init(document.getElementById('bar-chart'))
}
},
setOptions(opts) {
/** prop options */
if (opts) {
}
if (this.chart) this.chart.setOption(this.defaultOpts)
}
},
render: function(h) {
return h('div', { attrs: { id: 'bar-chart' }, style: { background: '#eee', width: '100%', height: '300px', padding: '8px' } }, '')
}
}
const dict = ['表格', '图形']
export default {
name: 'QualityInspectionCurrent',
components: { BaseTable, SmallTitle, FakeChart },
data() {
return {
tableConfigStatic,
tableConfigDynamic,
dataListStatic: [],
dataListDynamic: [],
dict,
dataType: dict[0], // |
showGraph: false,
datetime: [],
quickOptions: {
shortcuts: [
{
text: '今天',
onClick(picker) {
const baseTime = moment().set({ hour: 0, minute: 0, second: 0, millisecond: 0 })
const startTime = baseTime.format('yyyy-MM-DDTHH:mm:ss')
const endTime = baseTime.set({ hour: 23, minute: 59, second: 59, millisecond: 999 }).format('yyyy-MM-DDTHH:mm:ss')
picker.$emit('pick', [startTime, endTime])
}
}
]
},
echartCategories: null,
echartCheckTypes: []
}
},
mounted() {
this.getDataList()
},
methods: {
handleOperations() {},
handleDataTypeChange(value) {
this.showGraph = value === dict[0] ? false : true
},
getDataList() {
this.showGraph = false
this.dataType = '表格'
this.echartCategories = null
this.echartCheckTypes.splice(0)
/** 设置默认日期 */
const startTime =
this.datetime[0] ||
moment()
.set({ hour: 0, minute: 0, second: 0 })
.format('yyyy-MM-DDTHH:mm:ss')
const endTime =
this.datetime[1] ||
moment()
.set({ hour: 23, minute: 59, second: 59 })
.format('yyyy-MM-DDTHH:mm:ss')
/** [1] 获取上下片数据 */
this.fetchList('sx', startTime, endTime).then(({ data: res }) => {
console.log('sx: ', res)
this.dataListStatic = res.data || []
})
/** [2] 获取产线检测类型 */
this.fetchList('pl', startTime, endTime).then(({ data: res }) => {
console.log('pl: ', res)
/** TODO: 解析 nameData */
this.parseTableProps(res.data.nameData)
this.dataListDynamic = this.parseDynamicData(res.data.data) || []
this.buildGraphData()
})
},
parseTableProps(nameData) {
const subProps = []
const labelNameMap = new Map()
if (nameData.length) {
/** 处理 nameData */
nameData.forEach(item => {
if (!labelNameMap.get(item.name)) {
labelNameMap.set(item.name, 1)
subProps.push({ name: item.name, prop: item.name })
}
})
}
this.tableConfigDynamic = [
{ type: 'index', name: '序号' },
{ name: '检测类型', prop: 'inspectionContent' },
...subProps,
{ name: '检测类型总数', prop: 'sumInput' },
{ name: '比例', prop: 'scrapRatio', filter: val => (val || val === 0 ? `${val}%` : '-') }
]
/** echarts related */
this.echartCategories = subProps.map(item => item.name)
},
parseDynamicData(data) {
this.echartCheckTypes.splice(0)
return data.map(item => {
/** echarts related */
this.echartCheckTypes.push(item.inspectionContent)
if (item.data.length) {
/** 解析子数组 */
item.data.forEach(subitem => {
item[subitem.dynamicName] = subitem.dynamicValue
})
}
return item
})
},
buildGraphData() {
/** 构造 echart 需要的数据 */
const result = []
this.echartCheckTypes.forEach(ect => {
result.push({ name: ect, type: 'bar', data: [] })
})
this.dataListDynamic.forEach((inspection, index) => {
console.log('inspection: ', inspection)
this.echartCategories.forEach(cate => {
if (cate in inspection) {
result[index].data.push(inspection[cate])
} else {
result[index].data.push('0')
}
})
})
this.echartsData = result
// [
// { name: '11', type: 'bar', data: [/**线1*/ 2, /**线2*/ 3] },
// { name: '222', type: 'bar', data: [1, 2, 3] }
// ]
console.log('echarts data: ', this.echartsData)
},
fetchList(type, startTime, endTime) {
switch (type) {
case 'sx':
return this.$http({
url: this.$http.adornUrl('/monitoring/qualityInspectionRecord/pageCountRecordNow'),
method: 'POST',
data: {
startTime,
endTime
}
}).catch(err => {
console.error(err)
})
case 'pl':
return this.$http({
url: this.$http.adornUrl('/monitoring/qualityInspectionRecord/qualityInspectionRecordsDet'),
method: 'POST',
data: {
startTime,
endTime
}
}).catch(err => {
console.error(err)
})
}
}
}
}
</script>
<style scoped>
.base-container {
min-height: 60vh;
background: #fff;
padding: 12px;
}
</style>

View File

@ -9,34 +9,9 @@
<el-button v-if="$hasPermission('monitoring:qualityinspectionrecord:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
</el-form-item>
</el-form>
<!-- <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;">
<el-table-column type="selection" header-align="center" align="center" width="50"> </el-table-column>
<el-table-column prop="id" header-align="center" align="center" label="ID"> </el-table-column>
<el-table-column prop="inspectionDetId" header-align="center" align="center" label="检测内容id"> </el-table-column>
<el-table-column prop="inspectionDetContent" header-align="center" align="center" label="检测内容设备推送消息时可能无对应id只填这个字段"> </el-table-column>
<el-table-column prop="productionId" header-align="center" align="center" label="产线id"> </el-table-column>
<el-table-column prop="sectionId" header-align="center" align="center" label="工段id"> </el-table-column>
<el-table-column prop="checkPerson" header-align="center" align="center" label="检测人员,可以多个"> </el-table-column>
<el-table-column prop="checkTime" header-align="center" align="center" label="检测时间"> </el-table-column>
<el-table-column prop="source" header-align="center" align="center" label="来源 1手动默认 2自动"> </el-table-column>
<el-table-column prop="explainText" header-align="center" align="center" label="描述"> </el-table-column>
<el-table-column prop="remark" header-align="center" align="center" label="备注"> </el-table-column>
<el-table-column prop="valid" header-align="center" align="center" label="删除标志,是否有效:1 可用 0不可用"> </el-table-column>
<el-table-column prop="creatorId" header-align="center" align="center" label="创建人"> </el-table-column>
<el-table-column prop="creatorName" header-align="center" align="center" label="创建人姓名"> </el-table-column>
<el-table-column prop="createTime" header-align="center" align="center" label="创建时间"> </el-table-column>
<el-table-column prop="updaterId" header-align="center" align="center" label="更新人"> </el-table-column>
<el-table-column prop="updaterName" header-align="center" align="center" label="更新人姓名"> </el-table-column>
<el-table-column prop="updateTime" header-align="center" align="center" label="更新时间"> </el-table-column>
<el-table-column prop="version" header-align="center" align="center" label="版本号"> </el-table-column>
<el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
<template slot-scope="scope">
<el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
<el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
</template>
</el-table-column>
</el-table> -->
<base-table :data="dataList" :table-head-configs="tableConfigs" :max-height="500" @operate-event="handleOperations" @refreshDataList="getDataList" />
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
@ -47,8 +22,16 @@
layout="total, sizes, prev, pager, next, jumper"
>
</el-pagination>
<!-- 弹窗, 新增 / 修改 -->
<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" :configs="addOrUpdateConfigs" @refreshDataList="getDataList" @destory-dialog="addOrUpdateVisible = false" />
<add-or-update
v-if="addOrUpdateVisible"
ref="addOrUpdate"
:configs="addOrUpdateConfigs"
@refreshDataList="getDataList"
@destory-dialog="addOrUpdateVisible = false"
@select-change="handleSelectChange"
/>
</div>
</template>
@ -71,7 +54,7 @@ const tableConfigs = [
{ prop: 'sectionId', name: '工段id' },
{ prop: 'checkPerson', name: '检测人员' },
// { prop: 'checkPerson', name: '' },
{ prop: 'source', name: '来源' },
{ prop: 'source', name: '来源', filter: val => ({ 1: '手动', 2: '自动' }[val]) },
// { prop: 'source', name: ' 1 2' },
{ prop: 'explainText', name: '描述' },
{ prop: 'remark', name: '备注' },
@ -82,7 +65,27 @@ const addOrUpdateConfigs = {
type: 'dialog',
infoUrl: '/monitoring/qualityInspectionRecord',
fields: [
{name: '', label: '检测类型', type: 'select', options: []}
{ name: 'checkTime', label: '检测时间', type: 'date', props: { style: 'width: 100%', type: 'datetime' }, placeholder: '请选择检测时间' },
{ name: 'productionId', label: '产线', type: 'select', options: [] },
{ name: 'sectionId', label: '工段', type: 'select', options: [] },
{
name: 'source',
label: '来源',
type: 'select',
options: [
{ value: 1, label: '手动', default: true },
{ value: 2, label: '自动' }
]
},
{ name: 'inspectionDetId', label: '检测内容', type: 'select', options: [] },
{ name: 'checkPerson', label: '检测人员' },
{ name: 'explainText', label: '描述' },
'remark'
],
operations: [
{ name: 'cancel', showAlways: true },
{ name: 'save', url: '/monitoring/qualityInspectionRecord', permission: '', showOnEdit: false },
{ name: 'update', url: '/monitoring/qualityInspectionRecord', permission: '', showOnEdit: true }
]
}
@ -109,8 +112,78 @@ export default {
},
activated() {
this.getDataList()
this.getInspectionDet()
this.getWorkSections()
this.getProductLines()
},
methods: {
// handle
async handleSelectChange({ name, id }) {
if (name === 'productionId') {
// 线
await this.getWorkSections(id)
}
},
//
getInspectionDet() {
this.$http({
url: this.$http.adornUrl('/monitoring/qualityInspectionDet/page'),
method: 'get',
params: this.$http.adornParams({
page: this.pageIndex,
limit: this.pageSize,
key: this.dataForm.key
})
}).then(({ data: res }) => {
console.log('insdet:', res)
const insDetOpt = this.addOrUpdateConfigs.fields.find(item => item.name === 'inspectionDetId')
if (insDetOpt) {
insDetOpt.options = res.data.list.map(item => ({ value: item.id, label: item.content })) || []
}
})
},
// 线
getProductLines() {
this.$http({
url: this.$http.adornUrl('/monitoring/productionLine/page'),
method: 'get',
params: this.$http.adornParams({
// page: this.pageIndex,
// limit: this.pageSize,
// key: this.dataForm.key
})
}).then(({ data: res }) => {
const plOpt = this.addOrUpdateConfigs.fields.find(item => item.name === 'productionId')
if (plOpt) {
plOpt.options = res.data.list.map(item => ({ value: item.id, label: item.name })) || []
}
})
},
//
getWorkSections(lineId) {
this.$http({
url: this.$http.adornUrl('/monitoring/workshopSection/page'),
method: 'get',
params: lineId
? this.$http.adornParams({
// page: this.pageIndex,
// limit: this.pageSize,
// key: this.dataForm.key
lineId
})
: {}
}).then(({ data: res }) => {
if (res.data.total === 0) {
this.$message.error('该产线没有工段')
} else {
this.$message.success(`该产线有 ${res.data.total} 条工段`)
}
const wsOpt = this.addOrUpdateConfigs.fields.find(item => item.name === 'sectionId')
if (wsOpt) {
wsOpt.options = res.data.list.map(item => ({ value: item.id, label: item.name })) || []
}
})
},
//
getDataList() {
this.addOrUpdateVisible = false