add Quill Editor Component

This commit is contained in:
lb 2023-01-31 16:39:27 +08:00
parent e6fe05ae17
commit d834082538
8 changed files with 484 additions and 271 deletions

View File

@ -9,10 +9,7 @@
:header-cell-style="/** 重写表格样式 **/ { :header-cell-style="/** 重写表格样式 **/ {
padding: '8px 0', padding: '8px 0',
}" }"
:header-row-style="/** 重写表格样式 **/ { row-key="id"
color: 'red',
background: 'black',
}"
> >
<!-- @cell-mouse-enter="(row, col, cell, event) => $emit('cell-mouse-enter', row, col, cell, event)"> --> <!-- @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)"> --> <!-- @cell-mouse-leave="(row, col, cell, event) => $emit('cell-mouse-leave', row, col, cell, event)"> -->

View File

@ -1,290 +1,268 @@
<template> <template>
<el-dialog <el-dialog class="dialog-just-form" :visible.sync="selfVisible" @closed="resetForm" :distory-on-close="true" :close-on-click-modal="configs.clickModalToClose ?? true">
class="dialog-just-form" <!-- title -->
:visible.sync="selfVisible" <div slot="title" class="dialog-title">
@closed="resetForm" <h1 class="">
:distory-on-close="true" {{ detailMode ? "查看详情" : dataForm.id ? "编辑" : "新增" }}
> </h1>
<!-- title --> </div>
<div slot="title" class="dialog-title">
<h1 class="">
{{ detailMode ? "查看详情" : dataForm.id ? "编辑" : "新增" }}
</h1>
</div>
<!-- form --> <!-- form -->
<el-form ref="dataForm" :model="dataForm" v-loading="loadingStatus"> <el-form ref="dataForm" :model="dataForm" v-loading="loadingStatus">
<el-row <el-row v-for="(row, rowIndex) in configs.form.rows" :key="'row_' + rowIndex" :gutter="20">
v-for="(row, rowIndex) in configs.form.rows" <el-col v-for="(col, colIndex) in row" :key="colIndex" :span="24 / row.length">
:key="'row_' + rowIndex" <!-- 通过多个 col === null 可以控制更灵活的 span 大小 -->
:gutter="20" <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-col <el-select
v-for="(col, colIndex) in row" v-if="col.select"
:key="colIndex" v-model="dataForm[col.prop]"
:span="24 / row.length" clearable
> :disabled="detailMode"
<!-- 通过多个 col === null 可以控制更灵活的 span 大小 --> v-bind="col.elparams"
<el-form-item @change="handleSelectChange(col, $event)"
v-if="col !== null" >
:label="col.label" <el-option v-for="(opt, optIdx) in col.options" :key="'option_' + optIdx" :label="opt.label" :value="opt.value" />
:prop="col.prop" </el-select>
:rules="col.rules || null" <el-switch
> v-if="col.switch"
<el-input v-model="dataForm[col.prop]"
v-if="col.input" :active-value="col.activeValue ?? 1"
v-model="dataForm[col.prop]" :inactive-value="col.activeValue ?? 0"
clearable @change="handleSwitchChange"
:disabled="detailMode" :disabled="detailMode"
v-bind="col.elparams" />
/> <el-input v-if="col.textarea" type="textarea" v-model="dataForm[col.prop]" :disabled="detailMode" v-bind="col.elparams" />
<el-select <div class="" v-if="col.component" style="margin: 42px 0 0;">
v-if="col.select" <component :is="col.component" :key="'component_' + col.prop" />
v-model="dataForm[col.prop]" </div>
clearable <!-- add more... -->
:disabled="detailMode" </el-form-item>
v-bind="col.elparams" </el-col>
@change="handleSelectChange(col, $event)" </el-row>
> </el-form>
<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>
<!-- footer --> <!-- footer -->
<div slot="footer"> <div slot="footer">
<template v-for="(operate, index) in configs.form.operations"> <template v-for="(operate, index) in configs.form.operations">
<el-button <el-button v-if="showButton(operate)" :key="'operation_' + index" :type="operate.type" @click="handleBtnClick(operate)">{{
v-if="showButton(operate)" operate.label
:key="'operation_' + index" }}</el-button>
:type="operate.type" </template>
@click="handleBtnClick(operate)" <el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button>
>{{ operate.label }}</el-button </div>
> </el-dialog>
</template>
<el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button>
</div>
</el-dialog>
</template> </template>
<script> <script>
import { pick as __pick } from "@/utils/filters"; import { pick as __pick } from "@/utils/filters";
function reConstructTreeData(listObj) {
Object.keys(listObj).forEach((id) => {});
}
export default { export default {
name: "DialogJustForm", name: "DialogJustForm",
props: { props: {
configs: { configs: {
type: Object, type: Object,
default: () => ({}), default: () => ({
}, clickModalToClose: true,
}, forms: null
inject: ["urls"], }),
data() { },
const dataForm = {}; },
this.configs.form.rows.forEach((row) => { inject: ["urls"],
row.forEach((col) => { data() {
dataForm[col.prop] = col.default ?? null; const dataForm = {};
col.fetchData && this.configs.form.rows.forEach((row) => {
col.fetchData().then(({ data: res }) => { row.forEach((col) => {
console.log("[Fetch Data]", res.data.list); dataForm[col.prop] = col.default ?? null;
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))
);
},
resetForm(excludeId = false, immediate = false) { if (col.fetchData)
setTimeout( col.fetchData().then(({ data: res }) => {
() => { console.log("[Fetch Data]", res.data.list);
console.log("[Dialog Just Form] clearing form..."); if (res.code === 0 && res.data.list) {
Object.keys(this.dataForm).forEach((key) => { this.$set(
if (excludeId && key === "id") return; col,
this.dataForm[key] = null; "options",
}); res.data.list.map((i) => ({ label: i.name, value: i.id }))
this.$refs.dataForm.clearValidate(); );
}, // col.options = res.data.list;
immediate ? 0 : 100 } 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 **/ resetForm(excludeId = false, immediate = false) {
init(id, detailMode) { setTimeout(
this.selfVisible = true; () => {
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) { /** init **/
console.log("[dialog REUSE] clearing form validation..."); init(id, detailMode) {
// dialog dataForm [0] this.selfVisible = true;
this.$refs.dataForm.clearValidate();
}
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; console.log("[Dialog Just Form] init():", id, detailMode);
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;
}
});
},
/** handlers */ this.detailMode = detailMode ?? false;
handleSelectChange(col, eventValue) { this.$nextTick(() => {
// console.log("[dialog] select change: ", col, eventValue); this.dataForm.id = id || null;
this.$forceUpdate(); if (this.dataForm.id) {
}, //
handleSwitchChange(val) { this.loadingStatus = true;
console.log("[dialog] switch change: ", val, this.dataForm); this.$http.get(this.urls.base + `/${this.dataForm.id}`).then(({ data: res }) => {
}, if (res && res.code === 0) {
handleBtnClick(payload) { const dataFormKeys = Object.keys(this.dataForm);
console.log("btn click payload: ", payload); 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) { /** handlers */
switch (payload.name) { handleSelectChange(col, eventValue) {
case "cancel": // console.log("[dialog] select change: ", col, eventValue);
this.handleClose(); this.$forceUpdate();
break; },
case "reset": handleSwitchChange(val) {
this.resetForm(true, true); // true means exclude id, immediate execution console.log("[dialog] switch change: ", val, this.dataForm);
break; },
case "add": handleBtnClick(payload) {
case "update": { console.log("btn click payload: ", payload);
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() { if ("name" in payload) {
// this.resetForm(); switch (payload.name) {
this.selfVisible = false; 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> </script>
<style scoped> <style scoped>
.dialog-just-form >>> .el-dialog__body { .dialog-just-form >>> .el-dialog__body {
/* padding-top: 16px !important; /* padding-top: 16px !important;
padding-bottom: 16px !important; */ padding-bottom: 16px !important; */
padding-top: 0 !important; padding-top: 0 !important;
padding-bottom: 0 !important; padding-bottom: 0 !important;
} }
.el-select { .el-select {
width: 100% !important; width: 100% !important;
} }
.dialog-just-form >>> .el-dialog__header { .dialog-just-form >>> .el-dialog__header {
padding: 10px 20px 10px; padding: 10px 20px 10px;
/* background: linear-gradient(to bottom, rgba(0, 0, 0, 0.25), white); */ /* background: linear-gradient(to bottom, rgba(0, 0, 0, 0.25), white); */
} }
</style> </style>

View File

@ -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' } })
}
}

View File

@ -129,10 +129,17 @@ export default {
// page : // page :
if ("list" in res.data) { if ("list" in res.data) {
// real env: // real env:
this.dataList = res.data.list.map((item) => ({ this.dataList = res.data.list.map((item) => {
...item, // if (item.parentId || item.parendName) { /** && */
id: item._id ?? item.id, // //
})); // return this.reConstructDataList(res.data.list)
// } else {
return {
...item,
id: item._id ?? item.id,
};
// }
});
// this.dataList = res.data.records; // this.dataList = res.data.records;
this.totalPage = res.data.total; this.totalPage = res.data.total;
} else if ("records" in res.data) { } else if ("records" in res.data) {
@ -151,6 +158,11 @@ export default {
}); });
}, },
/** 针对树形结构的列表,进行服务器端返回的数据重排 */
reConstructDataList(list) {
// const parentIndex = list.forEach()
},
/** 处理 HeadForm 的操作 */ /** 处理 HeadForm 的操作 */
handleHeadformOperate(payload) { handleHeadformOperate(payload) {
// //

View File

@ -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...
},
};
}

View File

@ -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>

View File

@ -8,7 +8,7 @@ export default function () {
{ prop: "createTime", label: "添加时间", filter: timeFilter }, { prop: "createTime", label: "添加时间", filter: timeFilter },
{ prop: "name", label: "类型名称" }, { prop: "name", label: "类型名称" },
{ prop: "code", label: "类型编码" }, { prop: "code", label: "类型编码" },
{ prop: "description", label: "描述" }, // { prop: "description", label: "描述" },
{ prop: "remark", label: "备注" }, { prop: "remark", label: "备注" },
{ {
prop: "operations", prop: "operations",
@ -72,9 +72,28 @@ export default function () {
rules: { required: true, message: "not empty", trigger: "blur" }, rules: { required: true, message: "not empty", trigger: "blur" },
elparams: { placeholder: "请输入类型编码" }, 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: "备注" } }], [{ input: true, label: "备注", prop: "remark", elparams: { placeholder: "备注" } }],
[{ upload: true, label: "上传资料", prop: "upload", elparams: null }],
], ],
operations: [ operations: [
{ name: "add", label: "保存", type: "primary", permission: "pms:equipmentType:save", showOnEdit: false }, { name: "add", label: "保存", type: "primary", permission: "pms:equipmentType:save", showOnEdit: false },

View File

@ -7,7 +7,7 @@ import initConfig from './config';
import ListViewWithHead from '@/views/atomViews/ListViewWithHead.vue'; import ListViewWithHead from '@/views/atomViews/ListViewWithHead.vue';
export default { export default {
name: 'WorkSequenceView', name: 'MaterialTypeView',
components: { ListViewWithHead }, components: { ListViewWithHead },
provide() { provide() {
return { return {