fix: 🐛 模版发布支持共享

This commit is contained in:
“chenhuachun”
2026-04-10 00:20:47 +08:00
parent ac93eee92e
commit cd451f7bc7
4 changed files with 133 additions and 25 deletions

View File

@@ -60,7 +60,7 @@
发布模板
</ElButton>
<ElDropdown
v-else
v-else-if="!props.appMode"
split-button
type="primary"
size="small"
@@ -86,6 +86,29 @@
</template>
</ElDropdown>
<ElDropdown
v-if="props.appMode"
split-button
type="primary"
size="small"
@click="onPublishApp"
@command="onPublishCommand">
<span>发布</span>
<template #dropdown>
<ElDropdownMenu>
<ElDropdownItem command="publishApp" :icon="VtjIconPublish">
发布应用
</ElDropdownItem>
<ElDropdownItem command="template" :icon="VtjIconTemplate">
发布模板
</ElDropdownItem>
<ElDropdownItem command="coder" :icon="Download" divided>
项目出码
</ElDropdownItem>
</ElDropdownMenu>
</template>
</ElDropdown>
<Publisher
v-if="publisherVisible"
v-model="publisherVisible"
@@ -124,11 +147,13 @@
export interface Props {
onlyPublishTemplate?: boolean;
coder?: boolean;
appMode?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
onlyPublishTemplate: false,
coder: false
coder: false,
appMode: false
});
const { engine, designer } = useSelected();
@@ -227,6 +252,27 @@
}
};
const onCoder = async () => {
const project = engine.project.value;
if (!project) return;
const link = await engine.genSource();
if (link) {
createDialog({
width: '600px',
height: '200px',
title: '出码',
icon: Download,
content: h(Coder, { link })
});
}
};
const onPublishApp = () => {
const project = engine.project.value;
if (!project) return;
alert('onPublishApp');
};
const onPublishCommand = (command: string) => {
const project = engine.project.value;
if (!project) return;
@@ -240,21 +286,12 @@
case 'template':
onPublishToTemplate();
break;
}
};
const onCoder = async () => {
const project = engine.project.value;
if (!project) return;
const link = await engine.genSource();
if (link) {
createDialog({
width: '600px',
height: '200px',
title: '出码',
icon: Download,
content: h(Coder, { link })
});
case 'coder':
onCoder();
break;
case 'publishApp':
onPublishApp();
break;
}
};

View File

@@ -39,6 +39,14 @@
editor="select"
:options="getTemplateCategories"
required></XField>
<XField
label="更新类型"
name="type"
required
editor="radio"
:options="typeOptions"
:props="{ button: true }"
@change="handleTypeChange"></XField>
<XField
label="版本号"
name="version"
@@ -49,10 +57,9 @@
}"></XField>
<XField
label="公开"
name="share"
name="isShared"
editor="switch"
tip="非公共的模版即仅自己可以使用, 公开模版后不允许删除"
:disabled="true"
required>
</XField>
<XField
@@ -77,6 +84,7 @@
import { useOpenApi } from '../../hooks';
import { type PublishTemplateDto } from '../../../framework';
import { NAME_REGEX, VERSION_REGEX } from '../../../constants';
import { upgradeVersion } from '../../../utils';
export interface Props {
id?: string;
canvas: any;
@@ -92,18 +100,44 @@
const model = reactive({
name: props.name,
label: props.label,
share: false
isShared: false,
prodVersion: '',
version: upgradeVersion('patch'),
type: 'patch'
});
const isOwner = ref(false);
const userFile = ref();
const typeOptions = [
{
label: '版本升级',
value: 'major'
},
{
label: '特性更新',
value: 'minor'
},
{
label: '修订补丁',
value: 'patch'
}
];
const handleTypeChange = (type: any) => {
model.version = upgradeVersion(type, model.prodVersion);
};
if (props.id) {
getTemplateById(props.id).then((res) => {
if (res) {
const version = res.latestVersion?.version;
Object.assign(model, {
category: res.category,
version: res.latest
version: upgradeVersion('patch', version),
prodVersion: version,
isShared: res.isShared ?? res.share,
name: res.code
});
}
isOwner.value = !!res;
@@ -149,7 +183,6 @@
dsl: JSON.stringify(dsl),
cover,
category: '',
version: '',
platform,
...model
};
@@ -186,7 +219,7 @@
.v-actions-widget__cover {
position: relative;
width: 100%;
height: 300px;
height: 250px;
background-color: var(--el-fill-color-dark);
border: 1px solid var(--el-border-color);
.el-image {

View File

@@ -3,15 +3,18 @@ import type { AITopic, AIChat } from './types';
export interface TemplateDto {
id: string;
name: string;
code?: string;
label: string;
vip: boolean;
share: boolean;
share?: boolean;
isShared?: boolean;
cover: string;
author: string;
userId: string;
category: string;
latest: string;
platform: string;
latestVersion?: any;
}
export interface DictOption {
@@ -24,7 +27,8 @@ export interface PublishTemplateDto {
label: string;
category: string;
cover: Blob;
share: boolean;
share?: boolean;
isShared?: boolean;
version: string;
platform: string;
latest?: string;

View File

@@ -146,3 +146,37 @@ export function readJsonFile(file: File): Promise<any> {
reader.readAsText(file);
});
}
export function upgradeVersion(
type: 'major' | 'minor' | 'patch',
version?: string
) {
if (!version) return '0.1.0';
const versionParts = version.split('.').map((part) => parseInt(part, 10));
if (versionParts.length !== 3 || versionParts.some(isNaN)) {
throw new Error('Invalid version format. Expected format: x.y.z');
}
let [major, minor, patch] = versionParts;
switch (type) {
case 'major':
major += 1;
minor = 0;
patch = 0;
break;
case 'minor':
minor += 1;
patch = 0;
break;
case 'patch':
patch += 1;
break;
default:
throw new Error('Invalid version type. Expected: major, minor, or patch');
}
return `${major}.${minor}.${patch}`;
}