优化mb-form 兼容replaceAll写法

This commit is contained in:
吕金泽 2022-09-07 12:07:48 +08:00
parent accbc2890b
commit 5c59037a35
5 changed files with 23 additions and 19 deletions

View File

@ -37,7 +37,7 @@
</template>
<script setup>
import { ref, reactive, watch, onMounted, getCurrentInstance } from 'vue'
import { ref, reactive, watch, onMounted, getCurrentInstance, onBeforeUnmount } from 'vue'
import common from "../../../scripts/common";
const { proxy } = getCurrentInstance()

View File

@ -17,7 +17,7 @@
:file-list="fileList"
>
<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>
</template>
@ -246,13 +246,13 @@ export default {
if (accepts) {
for (var i = 0; i < accepts.length; i++) {
if (!this.validAccept(fileName, accepts[i])) {
this.$message.error('上传文件格式只能为:' + this.getSettingSuffixs().replaceAll(',', ''))
this.$message.error('上传文件格式只能为:' + this.getSettingSuffixs().replace(/,/g, ''))
return false
}
}
} else {
if (!this.validAccept(fileName, 'null')) {
this.$message.error('上传文件格式只能为:' + this.getAllSuffixs().replaceAll(',', ''))
this.$message.error('上传文件格式只能为:' + this.getAllSuffixs().replace(/,/g, ''))
return false
}
}

View File

@ -24,11 +24,11 @@
</template>
<script setup>
import { ref, reactive, getCurrentInstance, watch } from 'vue'
import { ref, reactive, watch } from 'vue'
import common from '@/scripts/common'
const { proxy } = getCurrentInstance()
import { ElNotification } from 'element-plus'
const rules = reactive(getRules())
const formData = ref(initFormData())
const formData = ref({})
const dataForm = ref()
const props = defineProps({
form: {
@ -58,8 +58,8 @@
},{ deep: true })
props.form.props = props.form.props || {}
proxy.$common.setDefaultValue(props.form.props, 'labelPosition', 'right')
proxy.$common.setDefaultValue(props.form.props, 'labelWidth', '120px')
common.setDefaultValue(props.form.props, 'labelPosition', 'right')
common.setDefaultValue(props.form.props, 'labelWidth', '')
if(props.add && props.add.formData){
formData.value = common.objectAssign(formData.value, props.add.formData)
@ -77,7 +77,7 @@
return _rules
}
function initFormData() {
function getData() {
var data = {}
props.form.rows.forEach(row => {
row.cols.forEach(col => {
@ -87,6 +87,10 @@
return data
}
function initFormData(){
formData.value = getData()
}
function getFormData(){
return formData.value
}
@ -95,9 +99,9 @@
dataForm.value.validate((valid) => {
if (valid) {
d.loading()
proxy.$post(props.form.request.url, formData.value).then(res => {
common.$post(props.form.request.url, formData.value).then(res => {
d.hideLoading()
proxy.$notify({
ElNotification({
title: '成功',
message: (!formData.value[props.primaryField] ? '创建' : '修改') + '成功',
type: 'success',
@ -113,9 +117,9 @@
function getDetail(id) {
formData.value = props.detail.formData || {}
if(props.detail && props.detail.request){
var _formData = initFormData()
var _formData = getData()
_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
for (var t in _formData) {
if ((data[t] || data[t] === 0) && (!props.detail.excludeAssign || props.detail.excludeAssign.indexOf(t) === -1)) {
@ -124,7 +128,7 @@
}
if(formData.value){
formData.value = common.objectAssign(_formData, formData.value)
} else {
}else{
formData.value = _formData
}
if(props.detail.handlerFormData){
@ -138,6 +142,6 @@
}
}
defineExpose({ save, getDetail, getFormData })
defineExpose({ save, getDetail, getFormData, initFormData })
</script>

View File

@ -1,5 +1,5 @@
function gen(groupPath, data){
var permissionPrefix = groupPath.replace(/^\//,'').replace(/\/\//, '/').replaceAll('/', ':')
var permissionPrefix = groupPath.replace(/^\//,'').replace(/\/\//, '/').replace(/\//g, ':')
var html = `<template>
<mb-list ref="magicList" v-bind="listOptions" />
<mb-dialog ref="formDialog" :title="magicFormTitle" @confirm-click="magicForm.save($event)" width="50%">
@ -21,7 +21,7 @@ function gen(groupPath, data){
permission: '${permissionPrefix}:save',
click: () => {
magicFormTitle.value = '添加'
formDialog.value.show()
formDialog.value.show(() => magicForm.value.initFormData())
}
}],
table: {

View File

@ -95,7 +95,7 @@ treeTable.treeNodeReplace = (fields, searchData, treeNode, text, childrenSearch,
treeTable.clearFont = (data, fields) => {
fields.forEach(field => {
data[field] = data[field].replaceAll(/<font.*?>(.*?)<\/font>/g,'$1')
data[field] = data[field].replace(/<font.*?>(.*?)<\/font>/g,'$1')
})
}