修复上传
This commit is contained in:
parent
7b6deaadec
commit
d0b05d251c
@ -1,5 +1,3 @@
|
||||
import OSS from 'ali-oss';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export const OSS_FILE_BUCKETS = {
|
||||
@ -13,7 +11,6 @@ export const OSS_FILE_BUCKETS = {
|
||||
svgasource: 'svgasource',
|
||||
} as const;
|
||||
|
||||
const OSS_BUCKET = import.meta.env.VITE_GLOB_OSS_BUCKET || 'tkm-likei';
|
||||
const OSS_URL = import.meta.env.VITE_GLOB_OSS_URL || '';
|
||||
|
||||
export function randomFilename(filename?: string) {
|
||||
@ -49,14 +46,23 @@ export async function simpleUploadFile(
|
||||
dir: string = OSS_FILE_BUCKETS.other,
|
||||
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);
|
||||
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 || '',
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref, watch } from 'vue';
|
||||
import { computed, reactive, ref, watch } from 'vue';
|
||||
|
||||
import {
|
||||
OSS_FILE_BUCKETS,
|
||||
getAccessImgUrl,
|
||||
simpleUploadFile,
|
||||
} from '#/api/legacy/oss';
|
||||
import { listPayOpenCountry } from '#/api/legacy/pay';
|
||||
import { regionConfigTable } from '#/api/legacy/system';
|
||||
import { addBanner, updateBanner } from '#/api/legacy/system';
|
||||
import {
|
||||
addBanner,
|
||||
getCountryAlls,
|
||||
regionConfigTable,
|
||||
updateBanner,
|
||||
} from '#/api/legacy/system';
|
||||
import AccountInput from '#/components/account-input.vue';
|
||||
|
||||
import {
|
||||
@ -46,6 +49,22 @@ const DISPLAY_POSITION_OPTIONS = [
|
||||
{ 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 = [
|
||||
{ label: '礼物背包', value: 'GIFT_PACK_BUY' },
|
||||
{ label: '进入房间', value: 'ENTER_ROOM' },
|
||||
@ -95,6 +114,20 @@ const countriesLoading = ref(false);
|
||||
const regionsLoading = ref(false);
|
||||
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 keyword = contentKeyword.value.trim().toLowerCase();
|
||||
const target = keyword
|
||||
@ -140,7 +173,10 @@ watch(
|
||||
roomSearchValue.value = String(form.params);
|
||||
}
|
||||
}
|
||||
void loadCountries();
|
||||
void Promise.all([
|
||||
loadCountries(),
|
||||
sysOrigin ? loadRegions(sysOrigin) : Promise.resolve(),
|
||||
]);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
@ -170,7 +206,7 @@ watch(
|
||||
async function loadCountries() {
|
||||
countriesLoading.value = true;
|
||||
try {
|
||||
countryOptions.value = await listPayOpenCountry();
|
||||
countryOptions.value = await getCountryAlls();
|
||||
} finally {
|
||||
countriesLoading.value = false;
|
||||
}
|
||||
@ -351,9 +387,44 @@ async function submitForm() {
|
||||
|
||||
<div class="field">
|
||||
<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"
|
||||
></SysOriginSelect>
|
||||
placeholder="请选择系统"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="field field--full">
|
||||
@ -436,37 +507,25 @@ async function submitForm() {
|
||||
<div class="label">区域</div>
|
||||
<Select option-label-prop="label"
|
||||
v-model:value="form.regionList"
|
||||
:options="regionSelectOptions"
|
||||
:loading="regionsLoading"
|
||||
allow-clear
|
||||
mode="multiple"
|
||||
>
|
||||
<SelectOption
|
||||
v-for="item in regionOptions"
|
||||
:key="item.id"
|
||||
:value="item.id"
|
||||
:label="`${item.regionName}`">
|
||||
{{ item.regionName }}
|
||||
</SelectOption>
|
||||
</Select>
|
||||
placeholder="请选择区域"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="field field--full">
|
||||
<div class="label">国家</div>
|
||||
<Select option-label-prop="label"
|
||||
v-model:value="selectCountryCodes"
|
||||
:options="countrySelectOptions"
|
||||
:loading="countriesLoading"
|
||||
allow-clear
|
||||
mode="multiple"
|
||||
placeholder="请选择国家"
|
||||
@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 class="field field--full">
|
||||
|
||||
@ -8,9 +8,9 @@ import {
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { useAccessStore } from '@vben/stores';
|
||||
|
||||
import { listPayOpenCountry } from '#/api/legacy/pay';
|
||||
import {
|
||||
bannerTable,
|
||||
getCountryAlls,
|
||||
deleteBanner,
|
||||
regionConfigTable,
|
||||
} from '#/api/legacy/system';
|
||||
@ -115,7 +115,7 @@ async function loadRegions(sysOrigin: string) {
|
||||
async function loadCountries() {
|
||||
countriesLoading.value = true;
|
||||
try {
|
||||
countries.value = await listPayOpenCountry();
|
||||
countries.value = await getCountryAlls();
|
||||
} finally {
|
||||
countriesLoading.value = false;
|
||||
}
|
||||
@ -236,7 +236,7 @@ function getStatusColor(record: Record<string, any>) {
|
||||
style="width: 200px"
|
||||
@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">
|
||||
搜索
|
||||
|
||||
@ -128,7 +128,7 @@ async function uploadFile(file: File) {
|
||||
|
||||
try {
|
||||
const result = await simpleUploadFile(file, dir, customFilename);
|
||||
item.status = result.res?.status || 200;
|
||||
item.status = 200;
|
||||
item.name = result.name || item.name;
|
||||
item.url = getAccessImgUrl(result.name || item.name);
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user