|
@@ -2,192 +2,85 @@
|
|
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
|
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
|
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
|
|
-#set ($subClassNameVar = $subClassNameVars.get($subIndex))
|
|
|
|
|
-#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
|
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
|
|
|
|
|
|
|
- import { computed, ref, h, onMounted,watch,nextTick } from 'vue';
|
|
|
|
|
- import { $t } from '#/locales';
|
|
|
|
|
-
|
|
|
|
|
-#if ($subTable.subJoinMany) ## 一对多
|
|
|
|
|
-import { Plus } from "@vben/icons";
|
|
|
|
|
-import { Button, Tabs, Checkbox, Input, Textarea, Select,RadioGroup,CheckboxGroup, DatePicker } from 'ant-design-vue';
|
|
|
|
|
-import type { OnActionClickParams } from '#/adapter/vxe-table';
|
|
|
|
|
-import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
|
|
|
|
-import { use${subSimpleClassName}GridColumns } from '../data';
|
|
|
|
|
-import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
|
|
|
|
-#else
|
|
|
|
|
-import { useVbenForm } from '#/adapter/form';
|
|
|
|
|
-import { use${subSimpleClassName}FormSchema } from '../data';
|
|
|
|
|
-import { get${subSimpleClassName}By${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
|
|
|
|
-#end
|
|
|
|
|
-
|
|
|
|
|
-const props = defineProps<{
|
|
|
|
|
- ${subJoinColumn.javaField}?: any // ${subJoinColumn.columnComment}(主表的关联字段)
|
|
|
|
|
-}>()
|
|
|
|
|
-
|
|
|
|
|
-#if ($subTable.subJoinMany) ## 一对多
|
|
|
|
|
-/** 表格操作按钮的回调函数 */
|
|
|
|
|
-function onActionClick({
|
|
|
|
|
- code,
|
|
|
|
|
- row,
|
|
|
|
|
- }: OnActionClickParams<${simpleClassName}Api.${subSimpleClassName}>) {
|
|
|
|
|
-switch (code) {
|
|
|
|
|
- case 'delete': {
|
|
|
|
|
- onDelete(row);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ import { useVbenModal } from '@vben/common-ui';
|
|
|
|
|
+ import { message } from 'ant-design-vue';
|
|
|
|
|
|
|
|
-const [${subSimpleClassName}Grid, ${subClassNameVar}GridApi] = useVbenVxeGrid({
|
|
|
|
|
-gridOptions: {
|
|
|
|
|
- columns: use${subSimpleClassName}GridColumns(onActionClick),
|
|
|
|
|
- border: true,
|
|
|
|
|
- showOverflow: true,
|
|
|
|
|
- autoResize: true,
|
|
|
|
|
- keepSource: true,
|
|
|
|
|
- rowConfig: {
|
|
|
|
|
- keyField: 'id',
|
|
|
|
|
- },
|
|
|
|
|
- pagerConfig: {
|
|
|
|
|
- enabled: false,
|
|
|
|
|
- },
|
|
|
|
|
- toolbarConfig: {
|
|
|
|
|
- enabled: false,
|
|
|
|
|
- },
|
|
|
|
|
-},
|
|
|
|
|
-});
|
|
|
|
|
-
|
|
|
|
|
-/** 删除${subTable.classComment} */
|
|
|
|
|
-const onDelete = async (row: ${simpleClassName}Api.${subSimpleClassName}) => {
|
|
|
|
|
-await ${subClassNameVar}GridApi.grid.remove(row);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/** 添加${subTable.classComment} */
|
|
|
|
|
-const handleAdd = async () => {
|
|
|
|
|
-await ${subClassNameVar}GridApi.grid.insertAt({} as ${simpleClassName}Api.${subSimpleClassName}, -1);
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ import { computed, ref } from 'vue';
|
|
|
|
|
+ import { $t } from '#/locales';
|
|
|
|
|
+ import { useVbenForm } from '#/adapter/form';
|
|
|
|
|
+ import { get${subSimpleClassName}, create${subSimpleClassName}, update${subSimpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
|
|
|
|
|
|
|
-/** 提供获取表格数据的方法供父组件调用 */
|
|
|
|
|
-defineExpose({
|
|
|
|
|
-getData: (): ${simpleClassName}Api.${subSimpleClassName}[] => {
|
|
|
|
|
- return [
|
|
|
|
|
- ...${subClassNameVar}GridApi.grid.getData(),
|
|
|
|
|
- ...${subClassNameVar}GridApi.grid.getInsertRecords().map((row) => {
|
|
|
|
|
- delete row.id;
|
|
|
|
|
- return row;
|
|
|
|
|
- }),
|
|
|
|
|
- ];
|
|
|
|
|
-},
|
|
|
|
|
-});
|
|
|
|
|
|
|
+ import { use${subSimpleClassName}FormSchema } from '../data';
|
|
|
|
|
|
|
|
-/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
|
|
|
|
-watch(
|
|
|
|
|
- () => props.${subJoinColumn.javaField},
|
|
|
|
|
- async (val) => {
|
|
|
|
|
- if (!val) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const emit = defineEmits(['success']);
|
|
|
|
|
+ const formData = ref<${simpleClassName}Api.${subSimpleClassName}>();
|
|
|
|
|
+ const getTitle = computed(() => {
|
|
|
|
|
+ return formData.value?.id
|
|
|
|
|
+ ? $t('ui.actionTitle.edit', ['${subTable.classComment}'])
|
|
|
|
|
+ : $t('ui.actionTitle.create', ['${subTable.classComment}']);
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- await nextTick();
|
|
|
|
|
- await ${subClassNameVar}GridApi.grid.loadData(await get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField}!));
|
|
|
|
|
- },
|
|
|
|
|
-);
|
|
|
|
|
-#else
|
|
|
|
|
-const [${subSimpleClassName}Form, ${subClassNameVar}FormApi] = useVbenForm({
|
|
|
|
|
-layout: 'horizontal',
|
|
|
|
|
-schema: use${subSimpleClassName}FormSchema(),
|
|
|
|
|
-showDefaultActions: false
|
|
|
|
|
-});
|
|
|
|
|
|
|
+ const [Form, formApi] = useVbenForm({
|
|
|
|
|
+ layout: 'horizontal',
|
|
|
|
|
+ schema: use${subSimpleClassName}FormSchema(),
|
|
|
|
|
+ showDefaultActions: false
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
-/** 暴露出表单校验方法和表单值获取方法 */
|
|
|
|
|
-defineExpose({
|
|
|
|
|
-validate: async () => {
|
|
|
|
|
- const { valid } = await ${subClassNameVar}FormApi.validate();
|
|
|
|
|
- return valid;
|
|
|
|
|
-},
|
|
|
|
|
-getValues: ${subClassNameVar}FormApi.getValues,
|
|
|
|
|
-});
|
|
|
|
|
|
|
+ const [Modal, modalApi] = useVbenModal({
|
|
|
|
|
+ async onConfirm() {
|
|
|
|
|
+ const { valid } = await formApi.validate();
|
|
|
|
|
+ if (!valid) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
|
|
|
|
-watch(
|
|
|
|
|
- () => props.${subJoinColumn.javaField},
|
|
|
|
|
- async (val) => {
|
|
|
|
|
- if (!val) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ modalApi.lock();
|
|
|
|
|
+ // 提交表单
|
|
|
|
|
+ const data = (await formApi.getValues()) as ${simpleClassName}Api.${subSimpleClassName};
|
|
|
|
|
+ data.${subJoinColumn.javaField} = formData.value?.${subJoinColumn.javaField};
|
|
|
|
|
+ try {
|
|
|
|
|
+ await (formData.value?.id ? update${subSimpleClassName}(data) : create${subSimpleClassName}(data));
|
|
|
|
|
+ // 关闭并提示
|
|
|
|
|
+ await modalApi.close();
|
|
|
|
|
+ emit('success');
|
|
|
|
|
+ message.success({
|
|
|
|
|
+ content: $t('ui.actionMessage.operationSuccess'),
|
|
|
|
|
+ key: 'action_process_msg',
|
|
|
|
|
+ });
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ modalApi.lock(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ async onOpenChange(isOpen: boolean) {
|
|
|
|
|
+ if (!isOpen) {
|
|
|
|
|
+ formData.value = undefined;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- await nextTick();
|
|
|
|
|
- await ${subClassNameVar}FormApi.setValues(await get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField}!));
|
|
|
|
|
- },
|
|
|
|
|
-);
|
|
|
|
|
-#end
|
|
|
|
|
|
|
+ // 加载数据
|
|
|
|
|
+ let data = modalApi.getData<${simpleClassName}Api.${subSimpleClassName}>();
|
|
|
|
|
+ if (!data) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (data.id) {
|
|
|
|
|
+ modalApi.lock();
|
|
|
|
|
+ try {
|
|
|
|
|
+ data = await get${subSimpleClassName}(data.id);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ modalApi.lock(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 设置到 values
|
|
|
|
|
+ formData.value = data;
|
|
|
|
|
+ await formApi.setValues(formData.value);
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
<template>
|
|
|
- #if ($subTable.subJoinMany) ## 一对多
|
|
|
|
|
- <${subSimpleClassName}Grid class="mx-4">
|
|
|
|
|
- #foreach($column in $subColumns)
|
|
|
|
|
- #if ($column.createOperation || $column.updateOperation)
|
|
|
|
|
- #set ($javaField = $column.javaField)
|
|
|
|
|
- #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
|
|
|
|
- #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
|
|
|
|
- <template #${javaField}="{ row }">
|
|
|
|
|
- <Input v-model:value="row.${javaField}" />
|
|
|
|
|
- </template>
|
|
|
|
|
- #elseif($column.htmlType == "imageUpload")## 图片上传
|
|
|
|
|
- <template #${javaField}="{ row }">
|
|
|
|
|
- <UploadImg v-model:value="row.${javaField}" />
|
|
|
|
|
- </template>
|
|
|
|
|
- #elseif($column.htmlType == "fileUpload")## 文件上传
|
|
|
|
|
- <template #${javaField}="{ row }">
|
|
|
|
|
- <UploadFile v-model:value="row.${javaField}" />
|
|
|
|
|
- </template>
|
|
|
|
|
- #elseif($column.htmlType == "editor")## 文本编辑器
|
|
|
|
|
- <template #${javaField}="{ row }">
|
|
|
|
|
- <Textarea v-model:value="row.${javaField}" />
|
|
|
|
|
- </template>
|
|
|
|
|
- #elseif($column.htmlType == "select")## 下拉框
|
|
|
|
|
- <template #${javaField}="{ row, column }">
|
|
|
|
|
- <Select v-model:value="row.${javaField}" class="w-full">
|
|
|
|
|
- <Select.Option v-for="option in column.params.options" :key="option.value" :value="option.value">
|
|
|
|
|
- {{ option.label }}
|
|
|
|
|
- </Select.Option>
|
|
|
|
|
- </Select>
|
|
|
|
|
- </template>
|
|
|
|
|
- #elseif($column.htmlType == "checkbox")## 多选框
|
|
|
|
|
- <template #${javaField}="{ row, column }">
|
|
|
|
|
- <CheckboxGroup v-model:value="row.${javaField}" :options="column.params.options" />
|
|
|
|
|
- </template>
|
|
|
|
|
- #elseif($column.htmlType == "radio")## 单选框
|
|
|
|
|
- <template #${javaField}="{ row, column }">
|
|
|
|
|
- <RadioGroup v-model:value="row.${javaField}" :options="column.params.options" />
|
|
|
|
|
- </template>
|
|
|
|
|
- #elseif($column.htmlType == "datetime")## 时间框
|
|
|
|
|
- <template #${javaField}="{ row }">
|
|
|
|
|
- <DatePicker
|
|
|
|
|
- v-model:value="row.${javaField}"
|
|
|
|
|
- :showTime="true"
|
|
|
|
|
- format="YYYY-MM-DD HH:mm:ss"
|
|
|
|
|
- valueFormat='x'
|
|
|
|
|
- />
|
|
|
|
|
- </template>
|
|
|
|
|
- #elseif($column.htmlType == "textarea")## 文本框
|
|
|
|
|
- <template #${javaField}="{ row }">
|
|
|
|
|
- <Textarea v-model:value="row.${javaField}" />
|
|
|
|
|
- </template>
|
|
|
|
|
- #end
|
|
|
|
|
- #end
|
|
|
|
|
- #end
|
|
|
|
|
- </${subSimpleClassName}Grid>
|
|
|
|
|
- <div class="flex justify-center">
|
|
|
|
|
- <Button :icon="h(Plus)" type="primary" ghost @click="handleAdd" v-access:code="['${subTable.moduleName}:${simpleClassName_strikeCase}:create']">
|
|
|
|
|
- {{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }}
|
|
|
|
|
- </Button>
|
|
|
|
|
- </div>
|
|
|
|
|
- #else
|
|
|
|
|
- <${subSimpleClassName}Form class="mx-4" />
|
|
|
|
|
- #end
|
|
|
|
|
|
|
+ <Modal :title="getTitle">
|
|
|
|
|
+ <Form class="mx-4" />
|
|
|
|
|
+ </Modal>
|
|
|
</template>
|
|
</template>
|