修复上传

This commit is contained in:
ZuoZuo 2026-04-11 00:38:52 +08:00
parent 7b6deaadec
commit d0b05d251c
4 changed files with 107 additions and 42 deletions

View File

@ -1,5 +1,3 @@
import OSS from 'ali-oss';
import { requestClient } from '#/api/request'; import { requestClient } from '#/api/request';
export const OSS_FILE_BUCKETS = { export const OSS_FILE_BUCKETS = {
@ -13,7 +11,6 @@ export const OSS_FILE_BUCKETS = {
svgasource: 'svgasource', svgasource: 'svgasource',
} as const; } as const;
const OSS_BUCKET = import.meta.env.VITE_GLOB_OSS_BUCKET || 'tkm-likei';
const OSS_URL = import.meta.env.VITE_GLOB_OSS_URL || ''; const OSS_URL = import.meta.env.VITE_GLOB_OSS_URL || '';
export function randomFilename(filename?: string) { export function randomFilename(filename?: string) {
@ -49,14 +46,23 @@ export async function simpleUploadFile(
dir: string = OSS_FILE_BUCKETS.other, dir: string = OSS_FILE_BUCKETS.other,
customFilename?: string, customFilename?: string,
) { ) {
const stsResult = await getOssSts();
const client = new OSS({
accessKeyId: stsResult.AccessKeyId,
accessKeySecret: stsResult.AccessKeySecret,
bucket: OSS_BUCKET,
endpoint: 'oss-accelerate.aliyuncs.com',
stsToken: stsResult.SecurityToken,
});
const filename = customFilename || randomFilename(file.name); const filename = customFilename || randomFilename(file.name);
return client.put(`${dir}/${filename}`, file); const formData = new FormData();
formData.append('file', file, filename);
const result = await requestClient.post<Record<string, string>>(
'/ali-yun/oss/upload',
formData,
{
headers: {
'Content-Type': 'multipart/form-data',
},
params: {
dir,
filename,
},
},
);
return {
name: result?.name || '',
};
} }

View File

@ -1,14 +1,17 @@
<script lang="ts" setup> <script lang="ts" setup>
import { reactive, ref, watch } from 'vue'; import { computed, reactive, ref, watch } from 'vue';
import { import {
OSS_FILE_BUCKETS, OSS_FILE_BUCKETS,
getAccessImgUrl, getAccessImgUrl,
simpleUploadFile, simpleUploadFile,
} from '#/api/legacy/oss'; } from '#/api/legacy/oss';
import { listPayOpenCountry } from '#/api/legacy/pay'; import {
import { regionConfigTable } from '#/api/legacy/system'; addBanner,
import { addBanner, updateBanner } from '#/api/legacy/system'; getCountryAlls,
regionConfigTable,
updateBanner,
} from '#/api/legacy/system';
import AccountInput from '#/components/account-input.vue'; import AccountInput from '#/components/account-input.vue';
import { import {
@ -46,6 +49,22 @@ const DISPLAY_POSITION_OPTIONS = [
{ name: '游戏', value: 'GAME' }, { name: '游戏', value: 'GAME' },
]; ];
const APP_PLATFORMS = [
{ label: 'iOS', value: 'iOS' },
{ label: 'Android', value: 'Android' },
];
const SHOWCASE_OPTIONS: Array<Record<string, any>> = [
{ label: '下架', value: false },
{ label: '上架', value: true },
];
const TYPE_OPTIONS = [
{ label: 'H5', value: 'H5' },
{ label: 'APP', value: 'APP' },
{ label: 'AD', value: 'AD' },
];
const CONTENT_OPTIONS = [ const CONTENT_OPTIONS = [
{ label: '礼物背包', value: 'GIFT_PACK_BUY' }, { label: '礼物背包', value: 'GIFT_PACK_BUY' },
{ label: '进入房间', value: 'ENTER_ROOM' }, { label: '进入房间', value: 'ENTER_ROOM' },
@ -95,6 +114,20 @@ const countriesLoading = ref(false);
const regionsLoading = ref(false); const regionsLoading = ref(false);
const form = reactive<Record<string, any>>(createForm()); const form = reactive<Record<string, any>>(createForm());
const regionSelectOptions = computed(() =>
regionOptions.value.map((item) => ({
label: String(item.regionName || item.id || '-'),
value: item.id,
})),
);
const countrySelectOptions = computed(() =>
countryOptions.value.map((item) => ({
label: String(item.aliasName || item.countryName || item.alphaTwo || '-'),
value: item.alphaTwo,
})),
);
const contentSuggestions = () => { const contentSuggestions = () => {
const keyword = contentKeyword.value.trim().toLowerCase(); const keyword = contentKeyword.value.trim().toLowerCase();
const target = keyword const target = keyword
@ -140,7 +173,10 @@ watch(
roomSearchValue.value = String(form.params); roomSearchValue.value = String(form.params);
} }
} }
void loadCountries(); void Promise.all([
loadCountries(),
sysOrigin ? loadRegions(sysOrigin) : Promise.resolve(),
]);
}, },
{ immediate: true }, { immediate: true },
); );
@ -170,7 +206,7 @@ watch(
async function loadCountries() { async function loadCountries() {
countriesLoading.value = true; countriesLoading.value = true;
try { try {
countryOptions.value = await listPayOpenCountry(); countryOptions.value = await getCountryAlls();
} finally { } finally {
countriesLoading.value = false; countriesLoading.value = false;
} }
@ -351,9 +387,44 @@ async function submitForm() {
<div class="field"> <div class="field">
<div class="label">状态</div> <div class="label">状态</div>
<SysOriginSelect v-model:value="form.showcase" <Select
v-model:value="form.showcase"
:options="SHOWCASE_OPTIONS"
allow-clear
option-label-prop="label"
placeholder="请选择状态"
/>
</div>
<div class="field">
<div class="label">平台</div>
<Select
v-model:value="form.platform"
:options="APP_PLATFORMS"
allow-clear
option-label-prop="label"
placeholder="请选择平台"
/>
</div>
<div class="field">
<div class="label">类型</div>
<Select
v-model:value="form.type"
:options="TYPE_OPTIONS"
allow-clear
option-label-prop="label"
placeholder="请选择类型"
/>
</div>
<div class="field">
<div class="label">系统</div>
<SysOriginSelect
v-model:value="form.sysOrigin"
:options="sysOriginOptions" :options="sysOriginOptions"
></SysOriginSelect> placeholder="请选择系统"
/>
</div> </div>
<div class="field field--full"> <div class="field field--full">
@ -436,37 +507,25 @@ async function submitForm() {
<div class="label">区域</div> <div class="label">区域</div>
<Select option-label-prop="label" <Select option-label-prop="label"
v-model:value="form.regionList" v-model:value="form.regionList"
:options="regionSelectOptions"
:loading="regionsLoading" :loading="regionsLoading"
allow-clear allow-clear
mode="multiple" mode="multiple"
> placeholder="请选择区域"
<SelectOption />
v-for="item in regionOptions"
:key="item.id"
:value="item.id"
:label="`${item.regionName}`">
{{ item.regionName }}
</SelectOption>
</Select>
</div> </div>
<div class="field field--full"> <div class="field field--full">
<div class="label">国家</div> <div class="label">国家</div>
<Select option-label-prop="label" <Select option-label-prop="label"
v-model:value="selectCountryCodes" v-model:value="selectCountryCodes"
:options="countrySelectOptions"
:loading="countriesLoading" :loading="countriesLoading"
allow-clear allow-clear
mode="multiple" mode="multiple"
placeholder="请选择国家"
@change="changeCountry" @change="changeCountry"
> />
<SelectOption
v-for="item in countryOptions"
:key="item.id"
:value="item.country?.alphaTwo"
:label="`${item.country?.aliasName || item.country?.enName || item.country?.alphaTwo}`">
{{ item.country?.aliasName || item.country?.enName || item.country?.alphaTwo }}
</SelectOption>
</Select>
</div> </div>
<div class="field field--full"> <div class="field field--full">

View File

@ -8,9 +8,9 @@ import {
import { Page } from '@vben/common-ui'; import { Page } from '@vben/common-ui';
import { useAccessStore } from '@vben/stores'; import { useAccessStore } from '@vben/stores';
import { listPayOpenCountry } from '#/api/legacy/pay';
import { import {
bannerTable, bannerTable,
getCountryAlls,
deleteBanner, deleteBanner,
regionConfigTable, regionConfigTable,
} from '#/api/legacy/system'; } from '#/api/legacy/system';
@ -115,7 +115,7 @@ async function loadRegions(sysOrigin: string) {
async function loadCountries() { async function loadCountries() {
countriesLoading.value = true; countriesLoading.value = true;
try { try {
countries.value = await listPayOpenCountry(); countries.value = await getCountryAlls();
} finally { } finally {
countriesLoading.value = false; countriesLoading.value = false;
} }
@ -236,7 +236,7 @@ function getStatusColor(record: Record<string, any>) {
style="width: 200px" style="width: 200px"
@change="handleSearch" @change="handleSearch"
:options="countries.map((item) => ({ label: `${item.country?.aliasName || item.country?.enName || item.country?.alphaTwo}`, value: item.country?.alphaTwo as any }))" :options="countries.map((item) => ({ label: `${item.aliasName || item.countryName || item.alphaTwo}`, value: item.alphaTwo as any }))"
/> />
<Button :loading="loading" type="primary" @click="handleSearch"> <Button :loading="loading" type="primary" @click="handleSearch">
搜索 搜索

View File

@ -128,7 +128,7 @@ async function uploadFile(file: File) {
try { try {
const result = await simpleUploadFile(file, dir, customFilename); const result = await simpleUploadFile(file, dir, customFilename);
item.status = result.res?.status || 200; item.status = 200;
item.name = result.name || item.name; item.name = result.name || item.name;
item.url = getAccessImgUrl(result.name || item.name); item.url = getAccessImgUrl(result.name || item.name);
} catch (error) { } catch (error) {