mirror of
https://gitee.com/ssssssss-team/magic-boot.git
synced 2025-02-07 20:32:49 +08:00
优化mb-form 兼容replaceAll写法
This commit is contained in:
parent
accbc2890b
commit
5c59037a35
@ -37,7 +37,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, watch, onMounted, getCurrentInstance } from 'vue'
|
import { ref, reactive, watch, onMounted, getCurrentInstance, onBeforeUnmount } from 'vue'
|
||||||
import common from "../../../scripts/common";
|
import common from "../../../scripts/common";
|
||||||
|
|
||||||
const { proxy } = getCurrentInstance()
|
const { proxy } = getCurrentInstance()
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
:file-list="fileList"
|
:file-list="fileList"
|
||||||
>
|
>
|
||||||
<el-button type="primary" icon="ElIconUploadFilled" :loading="uploadLoading" :disabled="!multiple && fileList.length == 1">{{ label }}</el-button>
|
<el-button type="primary" icon="ElIconUploadFilled" :loading="uploadLoading" :disabled="!multiple && fileList.length == 1">{{ label }}</el-button>
|
||||||
<div slot="tip" v-if="showTip" class="el-upload__tip">支持上传{{ getSettingSuffixs().replaceAll(',', ',') }}文件,且不超过{{ maxFileSize }}MB</div>
|
<div slot="tip" v-if="showTip" class="el-upload__tip">支持上传{{ getSettingSuffixs().replace(/,/g, ',') }}文件,且不超过{{ maxFileSize }}MB</div>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -246,13 +246,13 @@ export default {
|
|||||||
if (accepts) {
|
if (accepts) {
|
||||||
for (var i = 0; i < accepts.length; i++) {
|
for (var i = 0; i < accepts.length; i++) {
|
||||||
if (!this.validAccept(fileName, accepts[i])) {
|
if (!this.validAccept(fileName, accepts[i])) {
|
||||||
this.$message.error('上传文件格式只能为:' + this.getSettingSuffixs().replaceAll(',', ','))
|
this.$message.error('上传文件格式只能为:' + this.getSettingSuffixs().replace(/,/g, ','))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!this.validAccept(fileName, 'null')) {
|
if (!this.validAccept(fileName, 'null')) {
|
||||||
this.$message.error('上传文件格式只能为:' + this.getAllSuffixs().replaceAll(',', ','))
|
this.$message.error('上传文件格式只能为:' + this.getAllSuffixs().replace(/,/g, ','))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, getCurrentInstance, watch } from 'vue'
|
import { ref, reactive, watch } from 'vue'
|
||||||
import common from '@/scripts/common'
|
import common from '@/scripts/common'
|
||||||
const { proxy } = getCurrentInstance()
|
import { ElNotification } from 'element-plus'
|
||||||
const rules = reactive(getRules())
|
const rules = reactive(getRules())
|
||||||
const formData = ref(initFormData())
|
const formData = ref({})
|
||||||
const dataForm = ref()
|
const dataForm = ref()
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
form: {
|
form: {
|
||||||
@ -58,8 +58,8 @@
|
|||||||
},{ deep: true })
|
},{ deep: true })
|
||||||
|
|
||||||
props.form.props = props.form.props || {}
|
props.form.props = props.form.props || {}
|
||||||
proxy.$common.setDefaultValue(props.form.props, 'labelPosition', 'right')
|
common.setDefaultValue(props.form.props, 'labelPosition', 'right')
|
||||||
proxy.$common.setDefaultValue(props.form.props, 'labelWidth', '120px')
|
common.setDefaultValue(props.form.props, 'labelWidth', '')
|
||||||
|
|
||||||
if(props.add && props.add.formData){
|
if(props.add && props.add.formData){
|
||||||
formData.value = common.objectAssign(formData.value, props.add.formData)
|
formData.value = common.objectAssign(formData.value, props.add.formData)
|
||||||
@ -77,7 +77,7 @@
|
|||||||
return _rules
|
return _rules
|
||||||
}
|
}
|
||||||
|
|
||||||
function initFormData() {
|
function getData() {
|
||||||
var data = {}
|
var data = {}
|
||||||
props.form.rows.forEach(row => {
|
props.form.rows.forEach(row => {
|
||||||
row.cols.forEach(col => {
|
row.cols.forEach(col => {
|
||||||
@ -87,6 +87,10 @@
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initFormData(){
|
||||||
|
formData.value = getData()
|
||||||
|
}
|
||||||
|
|
||||||
function getFormData(){
|
function getFormData(){
|
||||||
return formData.value
|
return formData.value
|
||||||
}
|
}
|
||||||
@ -95,9 +99,9 @@
|
|||||||
dataForm.value.validate((valid) => {
|
dataForm.value.validate((valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
d.loading()
|
d.loading()
|
||||||
proxy.$post(props.form.request.url, formData.value).then(res => {
|
common.$post(props.form.request.url, formData.value).then(res => {
|
||||||
d.hideLoading()
|
d.hideLoading()
|
||||||
proxy.$notify({
|
ElNotification({
|
||||||
title: '成功',
|
title: '成功',
|
||||||
message: (!formData.value[props.primaryField] ? '创建' : '修改') + '成功',
|
message: (!formData.value[props.primaryField] ? '创建' : '修改') + '成功',
|
||||||
type: 'success',
|
type: 'success',
|
||||||
@ -113,9 +117,9 @@
|
|||||||
function getDetail(id) {
|
function getDetail(id) {
|
||||||
formData.value = props.detail.formData || {}
|
formData.value = props.detail.formData || {}
|
||||||
if(props.detail && props.detail.request){
|
if(props.detail && props.detail.request){
|
||||||
var _formData = initFormData()
|
var _formData = getData()
|
||||||
_formData[props.primaryField] = id
|
_formData[props.primaryField] = id
|
||||||
proxy.$get(props.detail.request.url, { [props.primaryField]: id }).then(res => {
|
common.$get(props.detail.request.url, { [props.primaryField]: id }).then(res => {
|
||||||
const { data } = res
|
const { data } = res
|
||||||
for (var t in _formData) {
|
for (var t in _formData) {
|
||||||
if ((data[t] || data[t] === 0) && (!props.detail.excludeAssign || props.detail.excludeAssign.indexOf(t) === -1)) {
|
if ((data[t] || data[t] === 0) && (!props.detail.excludeAssign || props.detail.excludeAssign.indexOf(t) === -1)) {
|
||||||
@ -124,7 +128,7 @@
|
|||||||
}
|
}
|
||||||
if(formData.value){
|
if(formData.value){
|
||||||
formData.value = common.objectAssign(_formData, formData.value)
|
formData.value = common.objectAssign(_formData, formData.value)
|
||||||
} else {
|
}else{
|
||||||
formData.value = _formData
|
formData.value = _formData
|
||||||
}
|
}
|
||||||
if(props.detail.handlerFormData){
|
if(props.detail.handlerFormData){
|
||||||
@ -138,6 +142,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({ save, getDetail, getFormData })
|
defineExpose({ save, getDetail, getFormData, initFormData })
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
function gen(groupPath, data){
|
function gen(groupPath, data){
|
||||||
var permissionPrefix = groupPath.replace(/^\//,'').replace(/\/\//, '/').replaceAll('/', ':')
|
var permissionPrefix = groupPath.replace(/^\//,'').replace(/\/\//, '/').replace(/\//g, ':')
|
||||||
var html = `<template>
|
var html = `<template>
|
||||||
<mb-list ref="magicList" v-bind="listOptions" />
|
<mb-list ref="magicList" v-bind="listOptions" />
|
||||||
<mb-dialog ref="formDialog" :title="magicFormTitle" @confirm-click="magicForm.save($event)" width="50%">
|
<mb-dialog ref="formDialog" :title="magicFormTitle" @confirm-click="magicForm.save($event)" width="50%">
|
||||||
@ -21,7 +21,7 @@ function gen(groupPath, data){
|
|||||||
permission: '${permissionPrefix}:save',
|
permission: '${permissionPrefix}:save',
|
||||||
click: () => {
|
click: () => {
|
||||||
magicFormTitle.value = '添加'
|
magicFormTitle.value = '添加'
|
||||||
formDialog.value.show()
|
formDialog.value.show(() => magicForm.value.initFormData())
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
table: {
|
table: {
|
||||||
|
@ -95,7 +95,7 @@ treeTable.treeNodeReplace = (fields, searchData, treeNode, text, childrenSearch,
|
|||||||
|
|
||||||
treeTable.clearFont = (data, fields) => {
|
treeTable.clearFont = (data, fields) => {
|
||||||
fields.forEach(field => {
|
fields.forEach(field => {
|
||||||
data[field] = data[field].replaceAll(/<font.*?>(.*?)<\/font>/g,'$1')
|
data[field] = data[field].replace(/<font.*?>(.*?)<\/font>/g,'$1')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user