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,10 +1,5 @@
<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"
:visible.sync="selfVisible"
@closed="resetForm"
:distory-on-close="true"
>
<!-- title --> <!-- title -->
<div slot="title" class="dialog-title"> <div slot="title" class="dialog-title">
<h1 class=""> <h1 class="">
@ -14,30 +9,11 @@
<!-- 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"
:gutter="20"
>
<el-col
v-for="(col, colIndex) in row"
:key="colIndex"
:span="24 / row.length"
>
<!-- 通过多个 col === null 可以控制更灵活的 span 大小 --> <!-- 通过多个 col === null 可以控制更灵活的 span 大小 -->
<el-form-item <el-form-item v-if="col !== null" :label="col.label" :prop="col.prop" :rules="col.rules || null">
v-if="col !== null" <el-input v-if="col.input" v-model="dataForm[col.prop]" clearable :disabled="detailMode" v-bind="col.elparams" />
: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 <el-select
v-if="col.select" v-if="col.select"
v-model="dataForm[col.prop]" v-model="dataForm[col.prop]"
@ -46,12 +22,7 @@
v-bind="col.elparams" v-bind="col.elparams"
@change="handleSelectChange(col, $event)" @change="handleSelectChange(col, $event)"
> >
<el-option <el-option v-for="(opt, optIdx) in col.options" :key="'option_' + optIdx" :label="opt.label" :value="opt.value" />
v-for="(opt, optIdx) in col.options"
:key="'option_' + optIdx"
:label="opt.label"
:value="opt.value"
/>
</el-select> </el-select>
<el-switch <el-switch
v-if="col.switch" v-if="col.switch"
@ -61,13 +32,10 @@
@change="handleSwitchChange" @change="handleSwitchChange"
:disabled="detailMode" :disabled="detailMode"
/> />
<el-input <el-input v-if="col.textarea" type="textarea" v-model="dataForm[col.prop]" :disabled="detailMode" v-bind="col.elparams" />
v-if="col.textarea" <div class="" v-if="col.component" style="margin: 42px 0 0;">
type="textarea" <component :is="col.component" :key="'component_' + col.prop" />
v-model="dataForm[col.prop]" </div>
:disabled="detailMode"
v-bind="col.elparams"
/>
<!-- add more... --> <!-- add more... -->
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -77,13 +45,9 @@
<!-- 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"
@click="handleBtnClick(operate)"
>{{ operate.label }}</el-button
>
</template> </template>
<el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button> <el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button>
</div> </div>
@ -93,12 +57,19 @@
<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"], inject: ["urls"],
@ -107,7 +78,8 @@ export default {
this.configs.form.rows.forEach((row) => { this.configs.form.rows.forEach((row) => {
row.forEach((col) => { row.forEach((col) => {
dataForm[col.prop] = col.default ?? null; dataForm[col.prop] = col.default ?? null;
col.fetchData &&
if (col.fetchData)
col.fetchData().then(({ data: res }) => { col.fetchData().then(({ data: res }) => {
console.log("[Fetch Data]", res.data.list); console.log("[Fetch Data]", res.data.list);
if (res.code === 0 && res.data.list) { if (res.code === 0 && res.data.list) {
@ -122,6 +94,23 @@ export default {
} }
// dataForm[col.prop] = col.default ?? null; // not perfect! // 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 { return {
@ -142,12 +131,8 @@ export default {
const showAlways = operate.showAlways ?? false; const showAlways = operate.showAlways ?? false;
const editMode = operate.showOnEdit && this.dataForm.id; const editMode = operate.showOnEdit && this.dataForm.id;
const addMode = !operate.showOnEdit && !this.dataForm.id; const addMode = !operate.showOnEdit && !this.dataForm.id;
const permission = operate.permission const permission = operate.permission ? this.$hasPermission(operate.permission) : true;
? this.$hasPermission(operate.permission) return notDetailMode && (showAlways || ((editMode || addMode) && permission));
: true;
return (
notDetailMode && (showAlways || ((editMode || addMode) && permission))
);
}, },
resetForm(excludeId = false, immediate = false) { resetForm(excludeId = false, immediate = false) {
@ -182,18 +167,13 @@ export default {
if (this.dataForm.id) { if (this.dataForm.id) {
// //
this.loadingStatus = true; this.loadingStatus = true;
this.$http this.$http.get(this.urls.base + `/${this.dataForm.id}`).then(({ data: res }) => {
.get(this.urls.base + `/${this.dataForm.id}`)
.then(({ data: res }) => {
if (res && res.code === 0) { if (res && res.code === 0) {
const dataFormKeys = Object.keys(this.dataForm); const dataFormKeys = Object.keys(this.dataForm);
console.log("keys ===> ", dataFormKeys); console.log("keys ===> ", dataFormKeys);
// console.log('data form keys: ', dataFormKeys, pick(res.data, dataFormKeys)) // console.log('data form keys: ', dataFormKeys, pick(res.data, dataFormKeys))
this.dataForm = __pick(res.data, dataFormKeys); this.dataForm = __pick(res.data, dataFormKeys);
console.log( console.log("pick(res.data, dataFormKeys) ===> ", __pick(res.data, dataFormKeys));
"pick(res.data, dataFormKeys) ===> ",
__pick(res.data, dataFormKeys)
);
} }
this.loadingStatus = false; this.loadingStatus = false;
}); });
@ -238,9 +218,7 @@ export default {
.then(({ data: res }) => { .then(({ data: res }) => {
console.log("[add&update] res is: ", res); console.log("[add&update] res is: ", res);
if (res.code === 0) { if (res.code === 0) {
this.$message.success( this.$message.success(payload.name === "add" ? "添加成功" : "更新成功");
payload.name === "add" ? "添加成功" : "更新成功"
);
this.$emit("refreshDataList"); this.$emit("refreshDataList");
this.loadingStatus = false; this.loadingStatus = false;
this.handleClose(); this.handleClose();
@ -248,7 +226,7 @@ export default {
}) })
.catch((errMsg) => { .catch((errMsg) => {
this.$message.error("参数错误:" + errMsg); this.$message.error("参数错误:" + errMsg);
if (this.loadingStatus) this.loadingStatus = false if (this.loadingStatus) this.loadingStatus = false;
}); });
} else { } else {
// //

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) => {
// if (item.parentId || item.parendName) { /** && */
// //
// return this.reConstructDataList(res.data.list)
// } else {
return {
...item, ...item,
id: item._id ?? item.id, 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'},
], ],
[{ textarea: true, label: "描述信息", prop: "description", elparams: { placeholder: "描述信息" } }], // 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: "描述信息" } }],
[{ 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 {