This commit is contained in:
2025-04-02 19:16:28 +08:00
parent 9d3945413a
commit e43f9230eb
31 changed files with 513 additions and 188 deletions

View File

@@ -1,7 +1,3 @@
<!--
- @Author XXX
- @Link XXX
-->
<template>
<ma-form-item
v-if="typeof props.component.display == 'undefined' || props.component.display === true"
@@ -130,6 +126,87 @@
</a-pagination>
</div>
</template>
<!-- 改动1、2、3下面template都是改动内容 -->
<template #footer v-else-if="component.allowCreate">
<div style="padding: 6px 0; text-align: center">
<!-- 新增columns属性onCreate -->
<a-popover
:title="component.createInfo ? component.createInfo.title : '无标题'"
trigger="click"
>
<a-button size="small" type="primary">点击新增</a-button>
<template #content>
<a-row :wrap="false">
<a-input
:style="{ width: '320px' }"
:placeholder="`请输入新增的${component.createInfo.title}`"
allow-clear
v-model="createItem"
/>
<a-button
type="primary"
@click="handleCreteSubmit(component.onCreate)"
:loading="createLoading"
>提交</a-button
>
</a-row>
</template>
</a-popover>
</div>
</template>
<template #footer v-else-if="component.allowNew && !component.allowCreate">
<div style="padding: 6px 0; text-align: center">
<a-popover :title="component.newInfo ? component.newInfo.title : '无标题'" trigger="click">
<a-button size="small" type="primary">快速新增</a-button>
<template #content>
<ma-form
@submit="handleContactFormSubmit"
v-model="contactFormData"
:columns="contactFormOptions"
ref="contactForm"
></ma-form>
</template>
</a-popover>
</div>
</template>
<template #footer v-else-if="component.allowAbbrNew && !component.allowCreate && !component.allowNew">
<div style="padding: 6px 0; text-align: center">
<a-popover
:title="component.abbrNewInfo ? component.abbrNewInfo.title : '无标题'"
trigger="click"
>
<a-button size="small" type="primary">快速新增缩略语</a-button>
<template #content>
<ma-form
@submit="handleAbbrFormSubmit"
v-model="abbrFormData"
:columns="abbrFormOptions"
ref="abbrForm"
></ma-form>
</template>
</a-popover>
</div>
</template>
<template
#footer
v-else-if="
component.allowStd && !component.allowAbbrNew && !component.allowCreate && !component.allowNew
"
>
<div style="padding: 6px 0; text-align: center">
<a-popover :title="component.stdInfo ? component.stdInfo.title : '无标题'" trigger="click">
<a-button size="small" type="primary">快速新增依据标准</a-button>
<template #content>
<ma-form
@submit="handleStdFormSubmit"
v-model="stdFormData"
:columns="stdFormOptions"
ref="stdForm"
></ma-form>
</template>
</a-popover>
</div>
</template>
</a-select>
</slot>
</ma-form-item>
@@ -141,6 +218,138 @@ import MaFormItem from "./form-item.vue"
import { get, isUndefined, set, xor, isObject, isBoolean } from "lodash-es"
import { runEvent } from "../js/event.js"
import { handlerCascader, loadDict } from "../js/networkRequest.js"
import { Message, Notification } from "@arco-design/web-vue"
// 改动2快速新增联系单位信息[耦合内容] - start
import { columnsOptions as contactColumnOption } from "@/views/datamanage/projContact/crudColumns"
import { columnsOptions as abbrColumnOption } from "@/views/datamanage/abbreviation/columnsOptions"
import useDictItemCrud from "@/views/datamanage/dictmanage/DataList/useCrudRef.ts"
import tool from "@/utils/tool"
import contactApi from "@/api/system/contact"
import abbrApi from "@/api/system/abbreviation"
import dictApi from "@/api/system/dict"
//// 1. 处理快速新增单位
const contactFormOptions = ref(
tool.renameKeyInArray(
contactColumnOption.filter((it) => it.dataIndex !== "id"),
"commonRules",
"rules"
)
)
const contactFormData = ref({})
const handleContactFormSubmit = async (data, done) => {
done(true)
try {
const res = await contactApi.save(data)
// 更新当前select的选项
const newInfo = {
label: res.data.name,
value: res.data.name,
disabled: false,
indeterminate: false
}
dictList.value["entrust_unit"].push(newInfo)
dictList.value["test_unit"].push(newInfo)
dictList.value["dev_unit"].push(newInfo)
// 清空当前数据
contactFormData.value = {}
Notification.success("添加成功,请回到输入框进行选择")
} catch (err) {
Notification.error("请求错误,请重试或在数据管理页面添加")
} finally {
done(false)
}
}
//// 2. 处理快速新增缩略语
const abbrFormOptions = ref(
tool.renameKeyInArray(
abbrColumnOption.filter((it) => it.dataIndex !== "id"),
"commonRules",
"rules"
)
)
const abbrFormData = ref({})
const handleAbbrFormSubmit = async (data, done) => {
done(true)
try {
const res = await abbrApi.save(data)
// 更新当前select的选项
const newInfo = {
label: res.data.title,
value: res.data.title,
disabled: false,
indeterminate: false
}
dictList.value["abbreviation"].push(newInfo)
// 清空当前数据
abbrFormData.value = {}
Notification.success("添加成功,请回到输入框进行选择")
} catch (err) {
Notification.error("请求错误,请重试或在数据管理页面添加")
} finally {
done(false)
}
}
//// 3. 处理快速依据标准
const { columns: dictColumnOptions } = useDictItemCrud()
const initStdFormData = {
status: "1",
code: "standard",
sort: 1
}
const stdFormData = ref(initStdFormData)
const stdFormOptions = computed(() => {
const options = tool.renameKeyInArray(
dictColumnOptions.value.filter(
(it) => it.dataIndex !== "id" && it.dataIndex !== "update_datetime" && it.dataIndex !== "key"
),
"commonRules",
"rules"
)
return options.map((it) => {
if (it.dataIndex === "doc_name") {
return {
...it,
rules: [{ required: true, message: "文档名称必填" }]
}
}
if (it.dataIndex === "publish_date") {
return {
...it,
rules: [{ required: true, message: "发布日期必填" }]
}
}
if (it.dataIndex === "source") {
return {
...it,
rules: [{ required: true, message: "来源机构必填" }]
}
}
return it
})
})
const handleStdFormSubmit = async (data, done) => {
done(true)
try {
const res = await dictApi.createDictItemStdFast(data)
// 更新当前select的选项
const newInfo = {
label: res.data.doc_name,
value: res.data.key,
disabled: false,
indeterminate: false
}
dictList.value["standard"].push(newInfo)
// 清空当前数据
stdFormData.value = initStdFormData
Notification.success("添加成功,请回到输入框进行选择")
} catch (err) {
Notification.error("请求错误,请重试或在数据管理页面添加")
} finally {
done(false)
}
}
// 改动2结束 - end
const props = defineProps({
component: Object,
@@ -159,8 +368,9 @@ const dictList = inject("dictList")
const formLoading = inject("formLoading")
const columns = inject("columns")
const getColumnService = inject("getColumnService")
const rv = async (ev, value = "") =>
const rv = async (ev, value = "") => {
await runEvent(props.component, ev, { formModel, getColumnService, columns }, value)
}
const index = props.customField ?? props.component.dataIndex
const dictIndex = index.match(/^(\w+\.)\d+\./)
@@ -172,6 +382,38 @@ const loading = ref(false)
const optionMap = ref({})
const keyword = ref("")
// 改动1新增按钮处理
const createItem = ref("") // 新增string
const createLoading = ref(false) // 新增loading状态
const handleCreteSubmit = async (onCreate) => {
// 判断是否为空
if (!createItem.value.trim()) {
Message.error("请填写新增内容")
return
}
createLoading.value = true
try {
const code = await onCreate(createItem.value)
// 处理回显内容-更新当前select的选项
const optionList = dictList.value[code]
const new_dict_item = {
label: createItem.value,
value: (optionList.length + 1).toString(),
disabled: false,
indeterminate: false
}
optionList.push(new_dict_item)
} catch (err) {
// 弹出错误
Message.error("新增出错")
} finally {
createItem.value = ""
createLoading.value = false
Notification.success("新增成功,请重新选择新增内容")
}
}
// 改动1结束
watch(
() => get(formModel.value, index),
(vl) => (value.value = vl)
@@ -271,6 +513,7 @@ const handlePage = async (page) => {
loading.value = false
}
// 搜索当前字典内容
const handlerFallback = (key) => {
return optionMap.value[key] || key
}

View File

@@ -11,7 +11,7 @@
:allow-clear="props.component.allowClear ?? true"
:disabled="props.component.disabled"
:readonly="props.component.readonly"
:auto-size="props.component.autoSize"
:auto-size="props.component.autoSize || true"
:error="props.component.error"
:placeholder="props.component.placeholder ?? `请输入${props.component.title}`"
:max-length="props.component.maxLength"