This commit is contained in:
lb 2023-06-30 17:05:10 +08:00
parent 257696028b
commit f4be2d1efe
2 changed files with 196 additions and 99 deletions

View File

@ -59,7 +59,7 @@
<!-- 生产环境 --> <!-- 生产环境 -->
<% if (process.env.VUE_APP_NODE_ENV === 'prod') { %> <% if (process.env.VUE_APP_NODE_ENV === 'prod') { %>
<script> <script>
window.SITE_CONFIG['apiURL'] = 'http://localhost:8080/renren-admin'; window.SITE_CONFIG['apiURL'] = 'http://10.196.233.155:8080/pms-am';
</script> </script>
<% } %> <% } %>
</head> </head>

View File

@ -1,5 +1,9 @@
<template> <template>
<el-dialog class="dialog-with-menu" :visible="dialogVisible" :destroy-on-close="false" @close="handleClose" <el-dialog
class="dialog-with-menu"
:visible="dialogVisible"
:destroy-on-close="false"
@close="handleClose"
:close-on-click-modal="configs.clickModalToClose ?? true"> :close-on-click-modal="configs.clickModalToClose ?? true">
<!-- title --> <!-- title -->
<div slot="title" class="dialog-title"> <div slot="title" class="dialog-title">
@ -10,14 +14,28 @@
<div class="dialog-body__inner relative"> <div class="dialog-body__inner relative">
<!-- v-if="dataForm.id && !detailMode && /属性|详情/.test(activeMenu) && $hasPermission()" --> <!-- v-if="dataForm.id && !detailMode && /属性|详情/.test(activeMenu) && $hasPermission()" -->
<el-button v-if="configs.allowAdd ?? (dataForm.id && !detailMode && /属性|详情|参数/.test(activeMenu))" plain <el-button
type="primary" size="small" class="at-right-top" style="margin-bottom: 16px" @click="handleAddParam()">+ v-if="configs.allowAdd ?? (dataForm.id && !detailMode && /属性|详情|参数/.test(activeMenu))"
添加</el-button> plain
type="primary"
size="small"
class="at-right-top"
style="margin-bottom: 16px"
@click="handleAddParam()">
+ 添加
</el-button>
<template v-if="dataForm.id && !detailMode && /附件/.test(activeMenu)"> <template v-if="dataForm.id && !detailMode && /附件/.test(activeMenu)">
<el-upload style="position: absolute; width: 100%; height: 0" name="files" :action="uploadUrl" <el-upload
:show-file-list="false" :headers="uploadHeaders" :on-success="handleUploadSuccess" style="position: absolute; width: 100%; height: 0"
name="files"
:action="uploadUrl"
:show-file-list="false"
:headers="uploadHeaders"
:on-success="handleUploadSuccess"
:before-upload="handleUploadCheck"> :before-upload="handleUploadCheck">
<el-button plain type="primary" size="small" class="at-right-top" style=""> <i class="el-icon-upload"></i> 上传 <el-button plain type="primary" size="small" class="at-right-top" style="">
<i class="el-icon-upload"></i>
上传
</el-button> </el-button>
</el-upload> </el-upload>
</template> </template>
@ -27,11 +45,12 @@
<!-- <el-tab-pane v-for="(tab, index) in configs.menu" :key="index" :label="tab.name" :name="tab.name"> --> <!-- <el-tab-pane v-for="(tab, index) in configs.menu" :key="index" :label="tab.name" :name="tab.name"> -->
<el-tab-pane v-for="(tab, index) in actualMenus" :key="index" :name="tab.name"> <el-tab-pane v-for="(tab, index) in actualMenus" :key="index" :name="tab.name">
<span class="slot" slot="label"> <span class="slot" slot="label">
<i :class="{ <i
'el-icon-edit': tab.key === 'info', :class="{
'el-icon-s-data': tab.key === 'attr', 'el-icon-edit': tab.key === 'info',
'el-icon-folder-opened': tab.key === 'attachment', 'el-icon-s-data': tab.key === 'attr',
}"></i> 'el-icon-folder-opened': tab.key === 'attachment',
}"></i>
{{ tab.name }} {{ tab.name }}
</span> </span>
@ -41,33 +60,72 @@
<el-form ref="dataForm" :model="dataForm" v-loading="loadingStatus"> <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-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"> <el-col v-for="(col, colIndex) in row" :key="colIndex" :span="24 / row.length">
<el-form-item :label="col.label" :prop="col.prop" :rules="col.rules || null" <el-form-item
:label="col.label"
:prop="col.prop"
:rules="col.rules || null"
v-show="!col.forceDisabled || (col.forceDisabled && dataForm.id)"> v-show="!col.forceDisabled || (col.forceDisabled && dataForm.id)">
<div v-if="col.forceDisabled && dataForm.id" class="force-disabled"> <div v-if="col.forceDisabled && dataForm.id" class="force-disabled">
<el-tag :key="col.key" :type="col.type">{{ dataForm[col.prop] || "-" }}</el-tag> <el-tag :key="col.key" :type="col.type">{{ dataForm[col.prop] || "-" }}</el-tag>
</div> </div>
<el-input v-if="col.input" v-model="dataForm[col.prop]" clearable <el-input
:disabled="disableCondition(col.prop)" v-bind="col.elparams" /> v-if="col.input"
<el-cascader v-if="col.cascader" v-model="dataForm[col.prop]" :options="col.options" v-model="dataForm[col.prop]"
:disabled="detailMode" v-bind="col.elparams"></el-cascader> clearable
<el-select v-if="col.select" v-model="dataForm[col.prop]" clearable :disabled="disableCondition(col.prop)"
:disabled="disableCondition(col.prop)" v-bind="col.elparams" v-bind="col.elparams" />
<el-cascader
v-if="col.cascader"
v-model="dataForm[col.prop]"
:options="col.options"
:disabled="detailMode"
v-bind="col.elparams"></el-cascader>
<el-select
v-if="col.select"
v-model="dataForm[col.prop]"
clearable
:disabled="disableCondition(col.prop)"
v-bind="col.elparams"
@change="handleSelectChange(col, $event)"> @change="handleSelectChange(col, $event)">
<el-option v-for="(opt, optIdx) in col.options" :key="'option_' + optIdx" :label="opt.label" <el-option
:value="opt.value" /> v-for="(opt, optIdx) in col.options"
:key="'option_' + optIdx"
:label="opt.label"
:value="opt.value">
<span>{{ opt.label }}</span>
<span v-if="col.customLabel" style="display: inline-clock; margin-left: 12px; font-size: 0.9em">
{{ opt[col.customLabel] || "-" }}
</span>
</el-option>
</el-select> </el-select>
<el-switch v-if="col.switch" v-model="dataForm[col.prop]" :active-value="1" :inactive-value="0" <el-switch
@change="handleSwitchChange" :disabled="disableCondition(col.prop)" /> v-if="col.switch"
<el-input v-if="col.textarea" type="textarea" v-model="dataForm[col.prop]" v-model="dataForm[col.prop]"
:disabled="disableCondition(col.prop)" v-bind="col.elparams" /> :active-value="1"
<quillEditor v-if="col.richInput" ref="quill-editor" v-model="dataForm[col.prop]" :inactive-value="0"
:options="col.quillConfig ?? defaultQuillConfig" style="margin-top: 42px" @change="handleSwitchChange"
:disabled="disableCondition(col.prop)" />
<el-input
v-if="col.textarea"
type="textarea"
v-model="dataForm[col.prop]"
:disabled="disableCondition(col.prop)"
v-bind="col.elparams" />
<quillEditor
v-if="col.richInput"
ref="quill-editor"
v-model="dataForm[col.prop]"
:options="col.quillConfig ?? defaultQuillConfig"
style="margin-top: 42px"
:disabled="disableCondition(col.prop)" /> :disabled="disableCondition(col.prop)" />
<div class="" v-if="col.component" style="margin: 42px 0 0"> <div class="" v-if="col.component" style="margin: 42px 0 0">
<!-- 下面这个 component 几乎是为 富文本 quill 定制的了... TODO后续可能会根据业务需求创建新的版本 --> <!-- 下面这个 component 几乎是为 富文本 quill 定制的了... TODO后续可能会根据业务需求创建新的版本 -->
<component :is="col.component" :key="'component_' + col.prop" <component
@update:modelValue="handleComponentModelUpdate(col.prop, $event)" :modelValue="dataForm[col.prop]" :is="col.component"
:key="'component_' + col.prop"
@update:modelValue="handleComponentModelUpdate(col.prop, $event)"
:modelValue="dataForm[col.prop]"
:mode="detailMode ? 'detail' : dataForm.id ? 'edit' : 'create'" /> :mode="detailMode ? 'detail' : dataForm.id ? 'edit' : 'create'" />
</div> </div>
<!-- add more... --> <!-- add more... -->
@ -79,13 +137,27 @@
<!-- 表格标签页 --> <!-- 表格标签页 -->
<div v-if="dataForm.id && tab.key === 'attr'" key="attr-list"> <div v-if="dataForm.id && tab.key === 'attr'" key="attr-list">
<BaseListTable :table-config="null" :column-config="filteredTableProps" :table-data="subList" <BaseListTable
@operate-event="handleTableRowOperate" :current-page="attrPage" :current-size="attrSize" :table-config="null"
:refresh-layout-key="Math.random()" v-loading="loadingStatus" /> :column-config="filteredTableProps"
:table-data="subList"
@operate-event="handleTableRowOperate"
:current-page="attrPage"
:current-size="attrSize"
:refresh-layout-key="Math.random()"
v-loading="loadingStatus" />
<!-- paginator --> <!-- paginator -->
<el-pagination class="" style="text-align: left" background @size-change="handleSizeChange" <el-pagination
@current-change="handlePageChange" :current-page.sync="attrPage" :page-sizes="[5, 10, 20]" class=""
:page-size="attrSize" :total="attrTotal" layout="total, sizes, prev, next"></el-pagination> style="text-align: left"
background
@size-change="handleSizeChange"
@current-change="handlePageChange"
:current-page.sync="attrPage"
:page-sizes="[5, 10, 20]"
:page-size="attrSize"
:total="attrTotal"
layout="total, sizes, prev, next"></el-pagination>
</div> </div>
<!-- 附件标签页 --> <!-- 附件标签页 -->
@ -111,7 +183,10 @@
</ul> </ul>
</div> </div>
<!-- img preview dialog --> <!-- img preview dialog -->
<el-dialog key="image-preview-dialog" class="image-preview-dialog" :visible.sync="imgPreviewDialogVisible" <el-dialog
key="image-preview-dialog"
class="image-preview-dialog"
:visible.sync="imgPreviewDialogVisible"
:append-to-body="true"> :append-to-body="true">
<div class="img-container"> <div class="img-container">
<img width="100%" :src="currentImgUrl" alt="" /> <img width="100%" :src="currentImgUrl" alt="" />
@ -123,15 +198,26 @@
</div> </div>
<!-- sub dialog --> <!-- sub dialog -->
<small-dialog :append-to-body="true" v-if="showSubDialog" ref="subDialog" :url="urls.subase" <small-dialog
:configs="configs.subDialog" :related-id="dataForm.id" @refreshDataList="getSubList"></small-dialog> :append-to-body="true"
v-if="showSubDialog"
ref="subDialog"
:url="urls.subase"
:configs="configs.subDialog"
:related-id="dataForm.id"
@refreshDataList="getSubList"></small-dialog>
<!-- 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 v-if="showButton(operate)" :key="'operation_' + index" :type="operate.type" <el-button
v-if="showButton(operate)"
:key="'operation_' + index"
:type="operate.type"
@click="handleBtnClick(operate)" @click="handleBtnClick(operate)"
:loading="(operate.name === 'add' || operate.name === 'update') && btnLoading">{{ operate.label }}</el-button> :loading="(operate.name === 'add' || operate.name === 'update') && btnLoading">
{{ operate.label }}
</el-button>
</template> </template>
<el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button> <el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button>
</div> </div>
@ -186,7 +272,7 @@ export default {
const dataForm = {}; const dataForm = {};
const autoDisabledQueue = []; const autoDisabledQueue = [];
const watingToRefreshQueue = []; const watingToRefreshQueue = [];
const cached = {} const cached = {};
this.configs.form.rows.forEach((row) => { this.configs.form.rows.forEach((row) => {
row.forEach((col) => { row.forEach((col) => {
@ -202,7 +288,7 @@ export default {
if (res.code === 0) { if (res.code === 0) {
if (col.cacheFetchedData) { if (col.cacheFetchedData) {
// cache fetched data // cache fetched data
cached[col.prop] = 'list' in res.data ? res.data.list : (Array.isArray(res.data) ? res.data : []) cached[col.prop] = "list" in res.data ? res.data.list : Array.isArray(res.data) ? res.data : [];
} }
if (!col.options || !col.options.length) { if (!col.options || !col.options.length) {
@ -211,13 +297,13 @@ export default {
"options", "options",
"list" in res.data "list" in res.data
? res.data.list.map((i) => ({ ? res.data.list.map((i) => ({
label: col.optionLabel ? i[col.optionLabel] : i.name, label: col.optionLabel ? i[col.optionLabel] : i.name,
value: col.optionValue ? i[col.optionValue] : i.id, value: col.optionValue ? i[col.optionValue] : i.id,
})) }))
: res.data.map((i) => ({ : res.data.map((i) => ({
label: col.optionLabel ? i[col.optionLabel] : i.name, label: col.optionLabel ? i[col.optionLabel] : i.name,
value: col.optionValue ? i[col.optionValue] : i.id, value: col.optionValue ? i[col.optionValue] : i.id,
})) }))
); );
} }
// col.options = res.data.list; // col.options = res.data.list;
@ -228,13 +314,13 @@ export default {
"options", "options",
"list" in res.data "list" in res.data
? res.data.list.map((i) => ({ ? res.data.list.map((i) => ({
label: col.optionLabel ? i[col.optionLabel] : i.name, label: col.optionLabel ? i[col.optionLabel] : i.name,
value: col.optionValue ? i[col.optionValue] : i.id, value: col.optionValue ? i[col.optionValue] : i.id,
})) }))
: res.data.map((i) => ({ : res.data.map((i) => ({
label: col.optionLabel ? i[col.optionLabel] : i.name, label: col.optionLabel ? i[col.optionLabel] : i.name,
value: col.optionValue ? i[col.optionValue] : i.id, value: col.optionValue ? i[col.optionValue] : i.id,
})) }))
); );
} }
} else { } else {
@ -322,30 +408,39 @@ export default {
mounted() { mounted() {
this.configs.form.rows.forEach((row) => { this.configs.form.rows.forEach((row) => {
row.forEach((col) => { row.forEach((col) => {
if (col.changeReflects && typeof col.changeReflects === 'object' && 'fromKey' in col.changeReflects && 'toProp' in col.changeReflects) { if (
col.changeReflects &&
typeof col.changeReflects === "object" &&
"fromKey" in col.changeReflects &&
"toProp" in col.changeReflects
) {
this.$watch( this.$watch(
() => this.dataForm[col.prop], () => this.dataForm[col.prop],
val => { (val) => {
if (val && (col.prop in this.cached)) { if (val && col.prop in this.cached) {
console.log("here changeReflects", col.prop, col.changeReflects.toProp, this.cached[col.prop]) console.log("here changeReflects", col.prop, col.changeReflects.toProp, this.cached[col.prop]);
if (typeof col.changeReflects.fromKey === 'string') { if (typeof col.changeReflects.fromKey === "string") {
this.dataForm[col.changeReflects.toProp] = this.cached[col.prop].find(item => item.id === val)?.[col.changeReflects.fromKey] this.dataForm[col.changeReflects.toProp] = this.cached[col.prop].find((item) => item.id === val)?.[
col.changeReflects.fromKey
];
} else if (Array.isArray(col.changeReflects.fromKey) && col.changeReflects.delimiter) { } else if (Array.isArray(col.changeReflects.fromKey) && col.changeReflects.delimiter) {
const foundItem = this.dataForm[col.changeReflects.toProp] = this.cached[col.prop].find(item => item.id === val) const foundItem = (this.dataForm[col.changeReflects.toProp] = this.cached[col.prop].find(
(item) => item.id === val
));
if (foundItem) { if (foundItem) {
const values = col.changeReflects.fromKey.map(key => foundItem[key]) const values = col.changeReflects.fromKey.map((key) => foundItem[key]);
this.dataForm[col.changeReflects.toProp] = values.join(col.changeReflects.delimiter) this.dataForm[col.changeReflects.toProp] = values.join(col.changeReflects.delimiter);
} else { } else {
this.dataForm[col.changeReflects.toProp] = col.changeReflects.delimiter this.dataForm[col.changeReflects.toProp] = col.changeReflects.delimiter;
console.log("[DialogWithMenu] mounted() 没找到对应数据") console.log("[DialogWithMenu] mounted() 没找到对应数据");
} }
} }
} }
}, },
{ {
immediate: false immediate: false,
} }
) );
} }
}); });
}); });
@ -354,8 +449,8 @@ export default {
watch: { watch: {
dialogVisible: function (val) { dialogVisible: function (val) {
if (!!val) { if (!!val) {
this.attrPage = 1 this.attrPage = 1;
this.attrSize = 10 this.attrSize = 10;
} }
}, },
}, },
@ -369,7 +464,9 @@ export default {
}); });
}, },
filteredTableProps() { filteredTableProps() {
return this.detailMode ? this.configs.table.props.filter((v) => v.prop !== "operations") : this.configs.table.props; return this.detailMode
? this.configs.table.props.filter((v) => v.prop !== "operations")
: this.configs.table.props;
}, },
uploadHeaders() { uploadHeaders() {
return { return {
@ -477,11 +574,11 @@ export default {
/** 返回的文件列表 */ /** 返回的文件列表 */
this.fileList = res.data.files this.fileList = res.data.files
? res.data.files.map((file) => ({ ? res.data.files.map((file) => ({
id: file.id, id: file.id,
name: file.fileUrl.split("/").pop(), name: file.fileUrl.split("/").pop(),
url: file.fileUrl, url: file.fileUrl,
typeCode: file.typeCode, typeCode: file.typeCode,
})) }))
: []; : [];
} }
} }
@ -520,14 +617,14 @@ export default {
this.currentImgUrl = URL.createObjectURL(res); this.currentImgUrl = URL.createObjectURL(res);
this.imgPreviewDialogVisible = true; this.imgPreviewDialogVisible = true;
} else if (/pdf/i.test(res.type)) { } else if (/pdf/i.test(res.type)) {
// pdf // pdf
let a = document.createElement('a') let a = document.createElement("a");
a.setAttribute('target', '_blank') a.setAttribute("target", "_blank");
a.href = URL.createObjectURL(res) a.href = URL.createObjectURL(res);
a.click() a.click();
console.log('before remove a ', a) console.log("before remove a ", a);
a.remove() a.remove();
console.log('removed a ', a) console.log("removed a ", a);
} else { } else {
this.$message({ this.$message({
message: "非图片和PDF文件请下载后预览", message: "非图片和PDF文件请下载后预览",
@ -601,7 +698,7 @@ export default {
} }
}); });
}) })
.catch((err) => { }); .catch((err) => {});
} }
} }
}, },
@ -685,7 +782,7 @@ export default {
this.$refs.dataForm[0].validate((passed, result) => { this.$refs.dataForm[0].validate((passed, result) => {
if (passed) { if (passed) {
// //
this.btnLoading = true this.btnLoading = true;
this.loadingStatus = true; this.loadingStatus = true;
const method = payload.name === "add" ? "POST" : "PUT"; const method = payload.name === "add" ? "POST" : "PUT";
@ -706,7 +803,7 @@ export default {
} }
// //
this.btnLoading = true this.btnLoading = true;
this.$http({ this.$http({
url: this.urls.base, url: this.urls.base,
method, method,
@ -716,7 +813,7 @@ export default {
}, },
}) })
.then(({ data: res }) => { .then(({ data: res }) => {
this.btnLoading = false this.btnLoading = false;
this.loadingStatus = false; this.loadingStatus = false;
console.log("[add&update] res is: ", res); console.log("[add&update] res is: ", res);
if (res.code === 0) { if (res.code === 0) {
@ -751,13 +848,13 @@ export default {
type: "error", type: "error",
duration: 2000, duration: 2000,
}); });
if (this.btnLoading) this.btnLoading = false if (this.btnLoading) this.btnLoading = false;
} }
}) })
.catch((errMsg) => { .catch((errMsg) => {
this.$message.error("参数错误:" + errMsg); this.$message.error("参数错误:" + errMsg);
if (this.loadingStatus) this.loadingStatus = false; if (this.loadingStatus) this.loadingStatus = false;
if (this.btnLoading) this.btnLoading = false if (this.btnLoading) this.btnLoading = false;
}); });
} else { } else {
this.$message.error("请核查字段信息"); this.$message.error("请核查字段信息");
@ -780,7 +877,7 @@ export default {
}, },
handleSizeChange(val) { handleSizeChange(val) {
this.attrPage = 1; this.attrPage = 1;
this.attrSize = val this.attrSize = val;
this.getSubList(1, val); this.getSubList(1, val);
}, },
@ -844,8 +941,8 @@ export default {
switch (type) { switch (type) {
case "delete": { case "delete": {
// //
console.log('delete....', data) console.log("delete....", data);
const itemName = typeof data === 'object' ? (data.attrName || data.name || data.material || data.id) : data const itemName = typeof data === "object" ? data.attrName || data.name || data.material || data.id : data;
return this.$confirm(`是否删除条目: ${itemName}`, "提示", { return this.$confirm(`是否删除条目: ${itemName}`, "提示", {
confirmButtonText: "确认", confirmButtonText: "确认",
cancelButtonText: "我再想想", cancelButtonText: "我再想想",
@ -869,7 +966,7 @@ export default {
} }
}); });
}) })
.catch((err) => { }); .catch((err) => {});
} }
case "edit": { case "edit": {
this.handleAddParam(data); /** data is ==> id */ this.handleAddParam(data); /** data is ==> id */
@ -898,7 +995,7 @@ export default {
/* border-bottom-color: #0b58ff; */ /* border-bottom-color: #0b58ff; */
/* } */ /* } */
.dialog-with-menu>>>.el-dialog__body { .dialog-with-menu >>> .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;
@ -910,7 +1007,7 @@ export default {
width: 100% !important; width: 100% !important;
} }
.dialog-with-menu>>>.el-dialog__header { .dialog-with-menu >>> .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); */
} }
@ -927,7 +1024,7 @@ export default {
} }
ul.file-list, ul.file-list,
ul.file-list>li { ul.file-list > li {
padding: 0; padding: 0;
margin: 0; margin: 0;
list-style: none; list-style: none;
@ -942,7 +1039,7 @@ ul.file-list>li {
flex-direction: column; flex-direction: column;
} }
ul.file-list>li { ul.file-list > li {
border-radius: 4px; border-radius: 4px;
background-color: #edededd2; background-color: #edededd2;
padding: 8px; padding: 8px;
@ -951,7 +1048,7 @@ ul.file-list>li {
justify-content: space-between; justify-content: space-between;
} }
ul.file-list>li:hover { ul.file-list > li:hover {
background-color: #ededed; background-color: #ededed;
} }