refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范

这个提交包含在:
wikiboss
2026-09-20 17:05:22 +08:00
父节点 de3cf8b870
当前提交 9fa1d1fbd0
共有 1679 个文件被更改,包括 204798 次插入 和 16817 次删除

查看文件

@@ -0,0 +1,108 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isIOS = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
const isAndroid = platformInfo.startsWith('android')
describe('ExtApi-UploadFile', () => {
if ( isMP) {
it('skip', async () => {
expect(1).toBe(1);
});
return;
}
const PAGE_PATH = '/pages/API/upload-file/upload-file'
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
});
if (isWeb || isMP) {
it('not support', async () => {
expect(1).toBe(1)
})
return
}
beforeEach(async () => {
await page.setData({
data:{jest_result: false}
})
});
if(!isMP) {
it('Check ', async () => {
await page.waitFor(600);
await page.callMethod('jest_uploadFile');
await page.waitFor(2000);
res = await page.data('data.jest_result');
expect(res).toBe(true);
});
it('Check files upload', async () => {
res = await page.callMethod('jest_files_upload')
await page.waitFor(2000);
res = await page.data('data.jest_result');
expect(res).toBe(true)
});
}
it('Check uni.env', async () => {
await page.callMethod('jest_uploadFile_with_uni_env');
await page.waitFor(3000);
res = await page.data('data.jest_result');
expect(res).toBe(true);
});
// 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
let version = process.env.uniTestPlatformInfo
let split = version.split(" ")
version = parseInt(split[split.length - 1])
if(!isIOS || version > 15) {
it('Check Upload File In UTS Module', async () => {
res = await page.callMethod('jest_uts_module_invoked')
await page.waitFor(2000);
res = await page.data('data.jest_result');
expect(res).toBe(true)
})
}
let shouldTestCookie = false
if (isAndroid && !isAppWebView) {
let version = process.env.uniTestPlatformInfo
version = parseInt(version.split(" ")[1])
shouldTestCookie = version > 9
}
if (!shouldTestCookie) {
return
}
it('Check Set Cookie', async () => {
res = await page.callMethod('jest_set_cookie')
await page.waitFor(2000);
res = await page.data('data.jest_result');
expect(res).toBe(true)
});
it('Check Delete Cookie', async () => {
res = await page.callMethod('jest_delete_cookie')
await page.waitFor(2000);
res = await page.data('data.jest_result');
expect(res).toBe(true)
});
it('Check without file or files', async () => {
res = await page.callMethod('jest_uploadFileWithoutFile')
await page.waitFor(2000);
res = await page.data('data.jest_result');
expect(res).toBe(true)
})
it('Check verify useragent count', async () => {
res = await page.callMethod('jest_uploadFileVerifyUA')
await page.waitFor(2000);
res = await page.data('data.jest_result');
expect(res).toBe(true)
})
});

查看文件

@@ -0,0 +1,307 @@
<template>
<!-- #ifdef APP -->
<scroll-view class="page-scroll-view">
<!-- #endif -->
<view>
<page-head :title="data.title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="demo">
<image v-if="data.imageSrc" :src="data.imageSrc" class="image" mode="widthFix"></image>
<text v-else class="uni-hello-addfile" @click="chooseImage">+ 选择图片</text>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
// #ifdef APP-ANDROID || APP-IOS || APP-HARMONY
import {
testInovkeUploadFile,
CommonOptions
} from '@/uni_modules/test-invoke-network-api'
// #endif
type DataType = {
title: string;
imageSrc: string;
task: UploadTask | null;
jest_result: boolean;
}
const data = reactive({
title: 'uploadFile',
imageSrc: '',
task: null,
//自动化测试例专用
jest_result: false,
} as DataType)
onUnload(() => {
data.imageSrc = '';
uni.hideLoading();
data.task?.abort();
})
const chooseImage = () => {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album'],
success: (res) => {
console.log('chooseImage success, temp path is', res.tempFilePaths[0])
var imageSrc = res.tempFilePaths[0]
uni.showLoading({
title: '上传中'
})
data.task = uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: imageSrc,
name: 'file',
formData: {
'user': 'test'
},
success: (res) => {
console.log('uploadImage success, res is:', res)
uni.showToast({
title: '上传成功',
icon: 'success',
duration: 1000
})
data.imageSrc = imageSrc
},
fail: (err) => {
console.log('uploadImage fail', err);
uni.showModal({
content: err.errMsg,
showCancel: false
});
},
complete: (res) => {
uni.hideLoading();
data.task = null
}
});
},
fail: (err) => {
console.log('chooseImage fail', err)
}
})
}
//自动化测试例专用
const jest_uploadFile = () => {
const imageSrc = "/static/test-image/logo.png";
uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: imageSrc,
name: 'file',
formData: {
'user': 'test'
},
success: () => {
data.jest_result = true;
},
fail: () => {
data.jest_result = false;
},
})
}
const jest_uploadFile_with_uni_env = () => {
/**
* 微信小程序只支持USER_DATA_PATH,且子目录未创建的情况下不能直接下载到子目录内
*/
const filePath = `${uni.env.USER_DATA_PATH}/uni-app.png`
uni.downloadFile({
url: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
filePath: filePath,
success: () => {
uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: filePath,
name: 'file',
success: () => {
data.jest_result = true;
},
fail: () => {
data.jest_result = false;
},
})
},
fail: () => {
data.jest_result = false
}
});
}
const jest_cookie_upload = (needCookie : boolean) => {
const imageSrc = "/static/test-image/logo.png";
uni.uploadFile({
url: 'https://request.dcloud.net.cn/api/http/header/upload',
filePath: imageSrc,
name: 'file',
success: (res : UploadFileSuccess) => {
const responseData = JSON.parseObject(res.data)
const errCode = responseData?.getNumber("errCode")
if (errCode != null && errCode == 1000) {
data.jest_result = needCookie ? false : true;
} else {
data.jest_result = needCookie ? true : false;
}
},
fail: () => {
data.jest_result = false;
},
})
}
const jest_set_cookie = () => {
uni.request({
url: "https://request.dcloud.net.cn/api/http/header/setCookie",
method: "GET",
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success: () => {
jest_cookie_upload(true)
},
fail: () => {
data.jest_result = false;
},
});
}
const jest_delete_cookie = () => {
uni.request({
url: "https://request.dcloud.net.cn/api/http/header/deleteCookie",
method: "GET",
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success: () => {
jest_cookie_upload(false)
},
fail: () => {
data.jest_result = false;
},
});
}
const jest_files_upload = () => {
const imageSrc = "/static/test-image/logo.png";
uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload',
files: [
{
name: "file1",
uri: imageSrc
} as UploadFileOptionFiles,
{
name: "file2",
uri: imageSrc
} as UploadFileOptionFiles
],
success: (res : UploadFileSuccess) => {
if (res.statusCode == 200) {
data.jest_result = true;
}
},
fail: () => {
data.jest_result = false;
},
})
}
const jest_uts_module_invoked = () => {
// #ifdef APP-ANDROID || APP-IOS || APP-HARMONY
testInovkeUploadFile({
success: (res : any) => {
data.jest_result = true
},
fail: (err : any) => {
data.jest_result = false
}
} as CommonOptions)
// #endif
}
const jest_uploadFileWithoutFile = () => {
const imageSrc = "/static/test-image/logo.png";
uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
formData: {
'user': 'test'
},
success: (res) => {
console.log("success: ",res);
data.jest_result = true;
},
fail: (err) => {
console.log("fail: ", err);
data.jest_result = false;
},
})
}
const jest_uploadFileVerifyUA = () => {
uni.uploadFile({
url: 'https://request.dcloud.net.cn/api/http/header/upload',
header:{
"User-Agent":"custom"
},
formData: {
'user': 'test'
},
success: (res : UploadFileSuccess) => {
const responseData = JSON.parseObject(res.data)
const innerData = responseData?.getJSON("data")
const header = innerData?.getJSON("requestHeaders")
const uas = header?.getArray("user-agent")
if(uas != null) {
data.jest_result = (uas.length == 1)
}
},
fail: () => {
data.jest_result = false;
},
})
}
defineExpose({
data,
jest_uploadFile,
jest_uploadFile_with_uni_env,
jest_set_cookie,
jest_delete_cookie,
jest_files_upload,
jest_uts_module_invoked,
jest_uploadFileWithoutFile,
jest_uploadFileVerifyUA
})
</script>
<style>
.image {
width: 100%;
}
.demo {
background: #fff;
padding: 25px;
justify-content: center;
align-items: center;
}
.uni-hello-addfile {
text-align: center;
background: #fff;
padding: 25px;
margin-top: 10px;
font-size: 19px;
color: #808080;
}
</style>