add Quill Editor Component
Esse commit está contido em:
pai
e6fe05ae17
commit
d834082538
@ -9,10 +9,7 @@
|
||||
:header-cell-style="/** 重写表格样式 **/ {
|
||||
padding: '8px 0',
|
||||
}"
|
||||
:header-row-style="/** 重写表格样式 **/ {
|
||||
color: 'red',
|
||||
background: 'black',
|
||||
}"
|
||||
row-key="id"
|
||||
>
|
||||
<!-- @cell-mouse-enter="(row, col, cell, event) => $emit('cell-mouse-enter', row, col, cell, event)"> -->
|
||||
<!-- @cell-mouse-leave="(row, col, cell, event) => $emit('cell-mouse-leave', row, col, cell, event)"> -->
|
||||
|
@ -1,290 +1,268 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
class="dialog-just-form"
|
||||
:visible.sync="selfVisible"
|
||||
@closed="resetForm"
|
||||
:distory-on-close="true"
|
||||
>
|
||||
<!-- title -->
|
||||
<div slot="title" class="dialog-title">
|
||||
<h1 class="">
|
||||
{{ detailMode ? "查看详情" : dataForm.id ? "编辑" : "新增" }}
|
||||
</h1>
|
||||
</div>
|
||||
<el-dialog class="dialog-just-form" :visible.sync="selfVisible" @closed="resetForm" :distory-on-close="true" :close-on-click-modal="configs.clickModalToClose ?? true">
|
||||
<!-- title -->
|
||||
<div slot="title" class="dialog-title">
|
||||
<h1 class="">
|
||||
{{ detailMode ? "查看详情" : dataForm.id ? "编辑" : "新增" }}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<!-- form -->
|
||||
<el-form ref="dataForm" :model="dataForm" v-loading="loadingStatus">
|
||||
<el-row
|
||||
v-for="(row, rowIndex) in configs.form.rows"
|
||||
:key="'row_' + rowIndex"
|
||||
:gutter="20"
|
||||
>
|
||||
<el-col
|
||||
v-for="(col, colIndex) in row"
|
||||
:key="colIndex"
|
||||
:span="24 / row.length"
|
||||
>
|
||||
<!-- 通过多个 col === null 可以控制更灵活的 span 大小 -->
|
||||
<el-form-item
|
||||
v-if="col !== null"
|
||||
:label="col.label"
|
||||
:prop="col.prop"
|
||||
:rules="col.rules || null"
|
||||
>
|
||||
<el-input
|
||||
v-if="col.input"
|
||||
v-model="dataForm[col.prop]"
|
||||
clearable
|
||||
:disabled="detailMode"
|
||||
v-bind="col.elparams"
|
||||
/>
|
||||
<el-select
|
||||
v-if="col.select"
|
||||
v-model="dataForm[col.prop]"
|
||||
clearable
|
||||
:disabled="detailMode"
|
||||
v-bind="col.elparams"
|
||||
@change="handleSelectChange(col, $event)"
|
||||
>
|
||||
<el-option
|
||||
v-for="(opt, optIdx) in col.options"
|
||||
:key="'option_' + optIdx"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
<el-switch
|
||||
v-if="col.switch"
|
||||
v-model="dataForm[col.prop]"
|
||||
:active-value="col.activeValue ?? 1"
|
||||
:inactive-value="col.activeValue ?? 0"
|
||||
@change="handleSwitchChange"
|
||||
:disabled="detailMode"
|
||||
/>
|
||||
<el-input
|
||||
v-if="col.textarea"
|
||||
type="textarea"
|
||||
v-model="dataForm[col.prop]"
|
||||
:disabled="detailMode"
|
||||
v-bind="col.elparams"
|
||||
/>
|
||||
<!-- add more... -->
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
<!-- form -->
|
||||
<el-form ref="dataForm" :model="dataForm" v-loading="loadingStatus">
|
||||
<el-row v-for="(row, rowIndex) in configs.form.rows" :key="'row_' + rowIndex" :gutter="20">
|
||||
<el-col v-for="(col, colIndex) in row" :key="colIndex" :span="24 / row.length">
|
||||
<!-- 通过多个 col === null 可以控制更灵活的 span 大小 -->
|
||||
<el-form-item v-if="col !== null" :label="col.label" :prop="col.prop" :rules="col.rules || null">
|
||||
<el-input v-if="col.input" v-model="dataForm[col.prop]" clearable :disabled="detailMode" v-bind="col.elparams" />
|
||||
<el-select
|
||||
v-if="col.select"
|
||||
v-model="dataForm[col.prop]"
|
||||
clearable
|
||||
:disabled="detailMode"
|
||||
v-bind="col.elparams"
|
||||
@change="handleSelectChange(col, $event)"
|
||||
>
|
||||
<el-option v-for="(opt, optIdx) in col.options" :key="'option_' + optIdx" :label="opt.label" :value="opt.value" />
|
||||
</el-select>
|
||||
<el-switch
|
||||
v-if="col.switch"
|
||||
v-model="dataForm[col.prop]"
|
||||
:active-value="col.activeValue ?? 1"
|
||||
:inactive-value="col.activeValue ?? 0"
|
||||
@change="handleSwitchChange"
|
||||
:disabled="detailMode"
|
||||
/>
|
||||
<el-input v-if="col.textarea" type="textarea" v-model="dataForm[col.prop]" :disabled="detailMode" v-bind="col.elparams" />
|
||||
<div class="" v-if="col.component" style="margin: 42px 0 0;">
|
||||
<component :is="col.component" :key="'component_' + col.prop" />
|
||||
</div>
|
||||
<!-- add more... -->
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
|
||||
<!-- footer -->
|
||||
<div slot="footer">
|
||||
<template v-for="(operate, index) in configs.form.operations">
|
||||
<el-button
|
||||
v-if="showButton(operate)"
|
||||
:key="'operation_' + index"
|
||||
:type="operate.type"
|
||||
@click="handleBtnClick(operate)"
|
||||
>{{ operate.label }}</el-button
|
||||
>
|
||||
</template>
|
||||
<el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<!-- footer -->
|
||||
<div slot="footer">
|
||||
<template v-for="(operate, index) in configs.form.operations">
|
||||
<el-button v-if="showButton(operate)" :key="'operation_' + index" :type="operate.type" @click="handleBtnClick(operate)">{{
|
||||
operate.label
|
||||
}}</el-button>
|
||||
</template>
|
||||
<el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { pick as __pick } from "@/utils/filters";
|
||||
|
||||
function reConstructTreeData(listObj) {
|
||||
Object.keys(listObj).forEach((id) => {});
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "DialogJustForm",
|
||||
props: {
|
||||
configs: {
|
||||
type: Object,
|
||||
default: () => ({}),
|
||||
},
|
||||
},
|
||||
inject: ["urls"],
|
||||
data() {
|
||||
const dataForm = {};
|
||||
this.configs.form.rows.forEach((row) => {
|
||||
row.forEach((col) => {
|
||||
dataForm[col.prop] = col.default ?? null;
|
||||
col.fetchData &&
|
||||
col.fetchData().then(({ data: res }) => {
|
||||
console.log("[Fetch Data]", res.data.list);
|
||||
if (res.code === 0 && res.data.list) {
|
||||
this.$set(
|
||||
col,
|
||||
"options",
|
||||
res.data.list.map((i) => ({ label: i.name, value: i.id }))
|
||||
);
|
||||
// col.options = res.data.list;
|
||||
} else {
|
||||
col.options.splice(0);
|
||||
}
|
||||
// dataForm[col.prop] = col.default ?? null; // not perfect!
|
||||
});
|
||||
});
|
||||
});
|
||||
return {
|
||||
loadingStatus: false,
|
||||
dataForm,
|
||||
detailMode: false,
|
||||
selfVisible: false,
|
||||
baseDialogConfig: null,
|
||||
};
|
||||
},
|
||||
created() {
|
||||
// console.log('[dialog] created!!! wouldn\'t create again...')
|
||||
},
|
||||
methods: {
|
||||
/** utitilities */
|
||||
showButton(operate) {
|
||||
const notDetailMode = !this.detailMode;
|
||||
const showAlways = operate.showAlways ?? false;
|
||||
const editMode = operate.showOnEdit && this.dataForm.id;
|
||||
const addMode = !operate.showOnEdit && !this.dataForm.id;
|
||||
const permission = operate.permission
|
||||
? this.$hasPermission(operate.permission)
|
||||
: true;
|
||||
return (
|
||||
notDetailMode && (showAlways || ((editMode || addMode) && permission))
|
||||
);
|
||||
},
|
||||
name: "DialogJustForm",
|
||||
props: {
|
||||
configs: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
clickModalToClose: true,
|
||||
forms: null
|
||||
}),
|
||||
},
|
||||
},
|
||||
inject: ["urls"],
|
||||
data() {
|
||||
const dataForm = {};
|
||||
this.configs.form.rows.forEach((row) => {
|
||||
row.forEach((col) => {
|
||||
dataForm[col.prop] = col.default ?? null;
|
||||
|
||||
resetForm(excludeId = false, immediate = false) {
|
||||
setTimeout(
|
||||
() => {
|
||||
console.log("[Dialog Just Form] clearing form...");
|
||||
Object.keys(this.dataForm).forEach((key) => {
|
||||
if (excludeId && key === "id") return;
|
||||
this.dataForm[key] = null;
|
||||
});
|
||||
this.$refs.dataForm.clearValidate();
|
||||
},
|
||||
immediate ? 0 : 100
|
||||
);
|
||||
},
|
||||
if (col.fetchData)
|
||||
col.fetchData().then(({ data: res }) => {
|
||||
console.log("[Fetch Data]", res.data.list);
|
||||
if (res.code === 0 && res.data.list) {
|
||||
this.$set(
|
||||
col,
|
||||
"options",
|
||||
res.data.list.map((i) => ({ label: i.name, value: i.id }))
|
||||
);
|
||||
// col.options = res.data.list;
|
||||
} else {
|
||||
col.options.splice(0);
|
||||
}
|
||||
// dataForm[col.prop] = col.default ?? null; // not perfect!
|
||||
});
|
||||
else if (col.fetchTreeData)
|
||||
col.fetchTreeData().then(({ data: res }) => {
|
||||
console.log("[Fetch Tree Data]", res.data.list);
|
||||
if (res.code === 0 && res.data.list) {
|
||||
// 把数据先重构成一个对象
|
||||
const obj = {};
|
||||
res.data.list.map((item) => {
|
||||
obj[item.id] = item;
|
||||
});
|
||||
// 过滤这个对象
|
||||
let filteredList = reConstructTreeData(obj);
|
||||
// 最后设置 options
|
||||
this.$set(col, "options", filteredList);
|
||||
} else {
|
||||
col.options.splice(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
return {
|
||||
loadingStatus: false,
|
||||
dataForm,
|
||||
detailMode: false,
|
||||
selfVisible: false,
|
||||
baseDialogConfig: null,
|
||||
};
|
||||
},
|
||||
created() {
|
||||
// console.log('[dialog] created!!! wouldn\'t create again...')
|
||||
},
|
||||
methods: {
|
||||
/** utitilities */
|
||||
showButton(operate) {
|
||||
const notDetailMode = !this.detailMode;
|
||||
const showAlways = operate.showAlways ?? false;
|
||||
const editMode = operate.showOnEdit && this.dataForm.id;
|
||||
const addMode = !operate.showOnEdit && !this.dataForm.id;
|
||||
const permission = operate.permission ? this.$hasPermission(operate.permission) : true;
|
||||
return notDetailMode && (showAlways || ((editMode || addMode) && permission));
|
||||
},
|
||||
|
||||
/** init **/
|
||||
init(id, detailMode) {
|
||||
this.selfVisible = true;
|
||||
resetForm(excludeId = false, immediate = false) {
|
||||
setTimeout(
|
||||
() => {
|
||||
console.log("[Dialog Just Form] clearing form...");
|
||||
Object.keys(this.dataForm).forEach((key) => {
|
||||
if (excludeId && key === "id") return;
|
||||
this.dataForm[key] = null;
|
||||
});
|
||||
this.$refs.dataForm.clearValidate();
|
||||
},
|
||||
immediate ? 0 : 100
|
||||
);
|
||||
},
|
||||
|
||||
if (this.$refs.dataForm) {
|
||||
console.log("[dialog REUSE] clearing form validation...");
|
||||
// 当不是首次渲染dialog的时候,一开始就清空验证信息,本组件的循环里只有一个 dataForm 所以只用取 [0] 即可
|
||||
this.$refs.dataForm.clearValidate();
|
||||
}
|
||||
/** init **/
|
||||
init(id, detailMode) {
|
||||
this.selfVisible = true;
|
||||
|
||||
console.log("[Dialog Just Form] init():", id, detailMode);
|
||||
if (this.$refs.dataForm) {
|
||||
console.log("[dialog REUSE] clearing form validation...");
|
||||
// 当不是首次渲染dialog的时候,一开始就清空验证信息,本组件的循环里只有一个 dataForm 所以只用取 [0] 即可
|
||||
this.$refs.dataForm.clearValidate();
|
||||
}
|
||||
|
||||
this.detailMode = detailMode ?? false;
|
||||
this.$nextTick(() => {
|
||||
this.dataForm.id = id || null;
|
||||
if (this.dataForm.id) {
|
||||
// 如果是编辑
|
||||
this.loadingStatus = true;
|
||||
this.$http
|
||||
.get(this.urls.base + `/${this.dataForm.id}`)
|
||||
.then(({ data: res }) => {
|
||||
if (res && res.code === 0) {
|
||||
const dataFormKeys = Object.keys(this.dataForm);
|
||||
console.log("keys ===> ", dataFormKeys);
|
||||
// console.log('data form keys: ', dataFormKeys, pick(res.data, dataFormKeys))
|
||||
this.dataForm = __pick(res.data, dataFormKeys);
|
||||
console.log(
|
||||
"pick(res.data, dataFormKeys) ===> ",
|
||||
__pick(res.data, dataFormKeys)
|
||||
);
|
||||
}
|
||||
this.loadingStatus = false;
|
||||
});
|
||||
} else {
|
||||
// 如果不是编辑
|
||||
this.selfVisible = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
console.log("[Dialog Just Form] init():", id, detailMode);
|
||||
|
||||
/** handlers */
|
||||
handleSelectChange(col, eventValue) {
|
||||
// console.log("[dialog] select change: ", col, eventValue);
|
||||
this.$forceUpdate();
|
||||
},
|
||||
handleSwitchChange(val) {
|
||||
console.log("[dialog] switch change: ", val, this.dataForm);
|
||||
},
|
||||
handleBtnClick(payload) {
|
||||
console.log("btn click payload: ", payload);
|
||||
this.detailMode = detailMode ?? false;
|
||||
this.$nextTick(() => {
|
||||
this.dataForm.id = id || null;
|
||||
if (this.dataForm.id) {
|
||||
// 如果是编辑
|
||||
this.loadingStatus = true;
|
||||
this.$http.get(this.urls.base + `/${this.dataForm.id}`).then(({ data: res }) => {
|
||||
if (res && res.code === 0) {
|
||||
const dataFormKeys = Object.keys(this.dataForm);
|
||||
console.log("keys ===> ", dataFormKeys);
|
||||
// console.log('data form keys: ', dataFormKeys, pick(res.data, dataFormKeys))
|
||||
this.dataForm = __pick(res.data, dataFormKeys);
|
||||
console.log("pick(res.data, dataFormKeys) ===> ", __pick(res.data, dataFormKeys));
|
||||
}
|
||||
this.loadingStatus = false;
|
||||
});
|
||||
} else {
|
||||
// 如果不是编辑
|
||||
this.selfVisible = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
if ("name" in payload) {
|
||||
switch (payload.name) {
|
||||
case "cancel":
|
||||
this.handleClose();
|
||||
break;
|
||||
case "reset":
|
||||
this.resetForm(true, true); // true means exclude id, immediate execution
|
||||
break;
|
||||
case "add":
|
||||
case "update": {
|
||||
this.$refs.dataForm.validate((passed, result) => {
|
||||
if (passed) {
|
||||
// 如果通过验证
|
||||
this.loadingStatus = true;
|
||||
const method = payload.name === "add" ? "POST" : "PUT";
|
||||
this.$http({
|
||||
url: this.urls.base,
|
||||
method,
|
||||
data: this.dataForm,
|
||||
})
|
||||
.then(({ data: res }) => {
|
||||
console.log("[add&update] res is: ", res);
|
||||
if (res.code === 0) {
|
||||
this.$message.success(
|
||||
payload.name === "add" ? "添加成功" : "更新成功"
|
||||
);
|
||||
this.$emit("refreshDataList");
|
||||
this.loadingStatus = false;
|
||||
this.handleClose();
|
||||
}
|
||||
})
|
||||
.catch((errMsg) => {
|
||||
this.$message.error("参数错误:" + errMsg);
|
||||
if (this.loadingStatus) this.loadingStatus = false
|
||||
});
|
||||
} else {
|
||||
// 没有通过验证
|
||||
// this.$message.error(JSON.stringify(result));
|
||||
this.$message.error("请核查字段信息");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("[x] 不是这么用的! 缺少name属性");
|
||||
}
|
||||
},
|
||||
/** handlers */
|
||||
handleSelectChange(col, eventValue) {
|
||||
// console.log("[dialog] select change: ", col, eventValue);
|
||||
this.$forceUpdate();
|
||||
},
|
||||
handleSwitchChange(val) {
|
||||
console.log("[dialog] switch change: ", val, this.dataForm);
|
||||
},
|
||||
handleBtnClick(payload) {
|
||||
console.log("btn click payload: ", payload);
|
||||
|
||||
handleClose() {
|
||||
// this.resetForm();
|
||||
this.selfVisible = false;
|
||||
},
|
||||
},
|
||||
if ("name" in payload) {
|
||||
switch (payload.name) {
|
||||
case "cancel":
|
||||
this.handleClose();
|
||||
break;
|
||||
case "reset":
|
||||
this.resetForm(true, true); // true means exclude id, immediate execution
|
||||
break;
|
||||
case "add":
|
||||
case "update": {
|
||||
this.$refs.dataForm.validate((passed, result) => {
|
||||
if (passed) {
|
||||
// 如果通过验证
|
||||
this.loadingStatus = true;
|
||||
const method = payload.name === "add" ? "POST" : "PUT";
|
||||
this.$http({
|
||||
url: this.urls.base,
|
||||
method,
|
||||
data: this.dataForm,
|
||||
})
|
||||
.then(({ data: res }) => {
|
||||
console.log("[add&update] res is: ", res);
|
||||
if (res.code === 0) {
|
||||
this.$message.success(payload.name === "add" ? "添加成功" : "更新成功");
|
||||
this.$emit("refreshDataList");
|
||||
this.loadingStatus = false;
|
||||
this.handleClose();
|
||||
}
|
||||
})
|
||||
.catch((errMsg) => {
|
||||
this.$message.error("参数错误:" + errMsg);
|
||||
if (this.loadingStatus) this.loadingStatus = false;
|
||||
});
|
||||
} else {
|
||||
// 没有通过验证
|
||||
// this.$message.error(JSON.stringify(result));
|
||||
this.$message.error("请核查字段信息");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("[x] 不是这么用的! 缺少name属性");
|
||||
}
|
||||
},
|
||||
|
||||
handleClose() {
|
||||
// this.resetForm();
|
||||
this.selfVisible = false;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dialog-just-form >>> .el-dialog__body {
|
||||
/* padding-top: 16px !important;
|
||||
/* padding-top: 16px !important;
|
||||
padding-bottom: 16px !important; */
|
||||
padding-top: 0 !important;
|
||||
padding-bottom: 0 !important;
|
||||
padding-top: 0 !important;
|
||||
padding-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.el-select {
|
||||
width: 100% !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.dialog-just-form >>> .el-dialog__header {
|
||||
padding: 10px 20px 10px;
|
||||
/* background: linear-gradient(to bottom, rgba(0, 0, 0, 0.25), white); */
|
||||
padding: 10px 20px 10px;
|
||||
/* background: linear-gradient(to bottom, rgba(0, 0, 0, 0.25), white); */
|
||||
}
|
||||
</style>
|
||||
|
@ -1,2 +1,65 @@
|
||||
import Quill from "quill"
|
||||
import 'quill/dist/quill.snow.css'
|
||||
|
||||
// 富文本组件
|
||||
export default {}
|
||||
export default {
|
||||
name: 'QuillRichInput',
|
||||
props: ['readonly', 'placeholder', 'scroll']
|
||||
,
|
||||
data() {
|
||||
return {
|
||||
ReadOnlyMode: false,
|
||||
Placeholder: '',
|
||||
ScrollingContainer: null
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
readonly(val) {
|
||||
this.ReadOnlyMode = val
|
||||
},
|
||||
placeholder(val) {
|
||||
this.Placeholder = val
|
||||
},
|
||||
scroll(val) {
|
||||
this.ScrollingContainer = val
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
console.log('[Quill Editor] ref:', this.$refs['quill-editor'])
|
||||
/** https://blog.csdn.net/qq_36947168/article/details/119486710 */
|
||||
/** https://quilljs.com/docs/modules/toolbar/ */
|
||||
const toolbarOptions = [
|
||||
[{ 'font': [] }],
|
||||
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
|
||||
['bold', 'italic', 'underline', 'strike'], // toggled buttons
|
||||
['blockquote', 'code-block'],
|
||||
|
||||
[{ 'header': 1 }, { 'header': 2 }], // custom button values
|
||||
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
|
||||
[{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
|
||||
[{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
|
||||
[{ 'direction': 'rtl' }], // text direction
|
||||
|
||||
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
|
||||
|
||||
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
|
||||
[{ 'align': [] }],
|
||||
|
||||
['clean'] // remove formatting button
|
||||
];
|
||||
// const editor = new Quill(this.$refs['quill-editor'], this.defaultConfig)
|
||||
const editor = new Quill(this.$refs['quill-editor'], {
|
||||
modules: {
|
||||
toolbar: toolbarOptions
|
||||
},
|
||||
theme: 'snow',
|
||||
readOnly: this.ReadOnlyMode,
|
||||
placeholder: this.Placeholder,
|
||||
scrollingContainer: this.ScrollingContainer
|
||||
})
|
||||
},
|
||||
methods: {},
|
||||
render: function (h) {
|
||||
return h('div', { ref: 'quill-editor', domProps: { id: 'quill-editor' } })
|
||||
}
|
||||
}
|
@ -129,10 +129,17 @@ export default {
|
||||
// page 场景:
|
||||
if ("list" in res.data) {
|
||||
// real env:
|
||||
this.dataList = res.data.list.map((item) => ({
|
||||
...item,
|
||||
id: item._id ?? item.id,
|
||||
}));
|
||||
this.dataList = res.data.list.map((item) => {
|
||||
// if (item.parentId || item.parendName) { /** && 也行 */
|
||||
// // 如果需要树形结构的列表
|
||||
// return this.reConstructDataList(res.data.list)
|
||||
// } else {
|
||||
return {
|
||||
...item,
|
||||
id: item._id ?? item.id,
|
||||
};
|
||||
// }
|
||||
});
|
||||
// this.dataList = res.data.records;
|
||||
this.totalPage = res.data.total;
|
||||
} else if ("records" in res.data) {
|
||||
@ -151,6 +158,11 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
/** 针对树形结构的列表,进行服务器端返回的数据重排 */
|
||||
reConstructDataList(list) {
|
||||
// const parentIndex = list.forEach()
|
||||
},
|
||||
|
||||
/** 处理 HeadForm 的操作 */
|
||||
handleHeadformOperate(payload) {
|
||||
// 查询,导出,导入,等等
|
||||
|
112
src/views/modules/pms/car/config.js
Arquivo normal
112
src/views/modules/pms/car/config.js
Arquivo normal
@ -0,0 +1,112 @@
|
||||
import TableOperaionComponent from "@/components/noTemplateComponents/operationComponent";
|
||||
import switchBtn from "@/components/noTemplateComponents/switchBtn";
|
||||
import QuillRichInput from "@/components/noTemplateComponents/richInput";
|
||||
import request from "@/utils/request";
|
||||
import { dictFilter } from '@/utils/filters'
|
||||
|
||||
export default function () {
|
||||
const tableProps = [
|
||||
{ prop: "name", label: "窑车号" },
|
||||
{ prop: "code", label: "编码" },
|
||||
{ prop: "typeDictValue", label: "过渡车", filter: val => ['否', '是'](val) },
|
||||
{ prop: "status", label: "状态", subcomponent: switchBtn }, // subcomponent
|
||||
{ prop: "currentQty", label: "载量" },
|
||||
{ prop: "currentPos", label: "当前位置" },
|
||||
{ prop: "description", label: "描述" },
|
||||
{ prop: "remark", label: "备注" },
|
||||
{
|
||||
prop: "operations",
|
||||
name: "操作",
|
||||
fixed: "right",
|
||||
width: 120,
|
||||
subcomponent: TableOperaionComponent,
|
||||
options: ["edit", { name: "delete", permission: "pms:car:delete" }],
|
||||
},
|
||||
];
|
||||
|
||||
const headFormFields = [
|
||||
{
|
||||
prop: 'name',
|
||||
label: "窑车号",
|
||||
input: true,
|
||||
default: { value: "" },
|
||||
bind: {
|
||||
// placeholder: '请输入产线名称或编码'
|
||||
placeholder: '请输入料仓名称'
|
||||
}
|
||||
},
|
||||
{
|
||||
button: {
|
||||
type: "primary",
|
||||
name: "查询",
|
||||
},
|
||||
},
|
||||
{
|
||||
button: {
|
||||
type: "primary",
|
||||
name: "新增",
|
||||
permission: "pms:materialStorage:save"
|
||||
},
|
||||
bind: {
|
||||
plain: true,
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* dialog config 有两个版本,一个适用于 DialogWithMenu 组件,另一个适用于 DialogJustForm 组件
|
||||
* 适用于 DialogWithMenu 组件的配置示例详见 blenderStep/config.js
|
||||
* 此为后者的配置:
|
||||
*/
|
||||
const dialogJustFormConfigs = {
|
||||
clickModalToClose: false,
|
||||
form: {
|
||||
rows: [
|
||||
[
|
||||
{
|
||||
input: true,
|
||||
label: "窑车号",
|
||||
prop: "name",
|
||||
rules: { required: true, message: "not empty", trigger: "blur" },
|
||||
elparams: { placeholder: "请输入窑车号" },
|
||||
},
|
||||
{
|
||||
input: true,
|
||||
label: "编码",
|
||||
prop: "code",
|
||||
rules: { required: true, message: "not empty", trigger: "blur" },
|
||||
elparams: { placeholder: "请输入料仓编码" },
|
||||
},
|
||||
],
|
||||
[{ component: QuillRichInput, label: "描述信息", prop: "description" }],
|
||||
[{ input: true, label: "备注", prop: "remark", elparams: { placeholder: "备注" } }],
|
||||
],
|
||||
operations: [
|
||||
{ name: "add", label: "保存", type: "primary", permission: "pms:car:save", showOnEdit: false },
|
||||
{ name: "update", label: "更新", type: "primary", permission: "pms:car:update", showOnEdit: true },
|
||||
{ name: "reset", label: "重置", type: "warning", showAlways: true },
|
||||
// { name: 'cancel', label: '取消', showAlways: true },
|
||||
],
|
||||
},
|
||||
};
|
||||
// 备注:弹窗弹出的时间和网速有关......
|
||||
|
||||
return {
|
||||
dialogConfigs: dialogJustFormConfigs,
|
||||
tableConfig: {
|
||||
table: null, // 此处可省略,el-table 上的配置项
|
||||
column: tableProps, // el-column-item 上的配置项
|
||||
},
|
||||
headFormConfigs: {
|
||||
rules: null, // 名称是由 BaseSearchForm.vue 组件固定的
|
||||
fields: headFormFields, // 名称是由 BaseSearchForm.vue 组件固定的
|
||||
},
|
||||
urls: {
|
||||
base: "/pms/car",
|
||||
page: "/pms/car/page",
|
||||
// subase: '/pms/blenderStepParam',
|
||||
// subpage: '/pms/blenderStepParam/page',
|
||||
// more...
|
||||
},
|
||||
};
|
||||
}
|
32
src/views/modules/pms/car/index.vue
Arquivo normal
32
src/views/modules/pms/car/index.vue
Arquivo normal
@ -0,0 +1,32 @@
|
||||
<template>
|
||||
<ListViewWithHead :table-config="tableConfig" :head-config="headFormConfigs" :dialog-configs="dialogConfigs" :listQueryExtra="['name']" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import initConfig from './config';
|
||||
import ListViewWithHead from '@/views/atomViews/ListViewWithHead.vue';
|
||||
|
||||
export default {
|
||||
name: 'CarView',
|
||||
components: { ListViewWithHead },
|
||||
provide() {
|
||||
return {
|
||||
urls: this.allUrls
|
||||
}
|
||||
},
|
||||
data() {
|
||||
const { tableConfig, headFormConfigs, urls, dialogConfigs } = initConfig.call(this);
|
||||
return {
|
||||
tableConfig,
|
||||
headFormConfigs,
|
||||
allUrls: urls,
|
||||
dialogConfigs,
|
||||
};
|
||||
},
|
||||
created() {},
|
||||
mounted() {},
|
||||
methods: {},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
@ -8,7 +8,7 @@ export default function () {
|
||||
{ prop: "createTime", label: "添加时间", filter: timeFilter },
|
||||
{ prop: "name", label: "类型名称" },
|
||||
{ prop: "code", label: "类型编码" },
|
||||
{ prop: "description", label: "描述" },
|
||||
// { prop: "description", label: "描述" },
|
||||
{ prop: "remark", label: "备注" },
|
||||
{
|
||||
prop: "operations",
|
||||
@ -72,9 +72,28 @@ export default function () {
|
||||
rules: { required: true, message: "not empty", trigger: "blur" },
|
||||
elparams: { placeholder: "请输入类型编码" },
|
||||
},
|
||||
{
|
||||
prop: "parentId",
|
||||
select: true,
|
||||
options: [
|
||||
// {label: '父类1', value: '1'},
|
||||
// {label: '父类2', value: '2'},
|
||||
],
|
||||
// fetchData() 获取普通列表数据
|
||||
// fetchTreeData() 获取需要展示层级结构的数据
|
||||
fetchTreeData: () => {
|
||||
return this.$http.get('/pms/equipmentType/page', {
|
||||
limit: 999, page: 1, key: ""
|
||||
})
|
||||
},
|
||||
label: "父类",
|
||||
rules: { required: true, message: "not empty", trigger: "change" },
|
||||
elparams: { placeholder: "请输选择父类" },
|
||||
},
|
||||
],
|
||||
[{ textarea: true, label: "描述信息", prop: "description", elparams: { placeholder: "描述信息" } }],
|
||||
// [{ textarea: true, label: "描述信息", prop: "description", elparams: { placeholder: "描述信息" } }],
|
||||
[{ input: true, label: "备注", prop: "remark", elparams: { placeholder: "备注" } }],
|
||||
[{ upload: true, label: "上传资料", prop: "upload", elparams: null }],
|
||||
],
|
||||
operations: [
|
||||
{ name: "add", label: "保存", type: "primary", permission: "pms:equipmentType:save", showOnEdit: false },
|
||||
|
@ -7,7 +7,7 @@ import initConfig from './config';
|
||||
import ListViewWithHead from '@/views/atomViews/ListViewWithHead.vue';
|
||||
|
||||
export default {
|
||||
name: 'WorkSequenceView',
|
||||
name: 'MaterialTypeView',
|
||||
components: { ListViewWithHead },
|
||||
provide() {
|
||||
return {
|
||||
|
Carregando…
Referência em uma nova issue
Block a user