上传头像
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { TUILogin } from "@tencentcloud/tui-core";
|
||||
|
||||
let vueVersion = 3;
|
||||
function TUIlogin(
|
||||
chatInfo,
|
||||
info,
|
||||
userSig,
|
||||
) {
|
||||
uni.$SDKAppID = chatInfo.appId; // Your SDKAppID
|
||||
uni.$userID = info.userChatId; // Your userID
|
||||
uni.$SDKAppID = chatInfo; // Your SDKAppID
|
||||
uni.$userID = String(info); // Your userID
|
||||
uni.$userSig = userSig; // Your userSig
|
||||
TUILogin.login({
|
||||
SDKAppID: uni.$SDKAppID,
|
||||
|
||||
19
components/generateFileName.js
Normal file
19
components/generateFileName.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// 生成 6位随机字符(包含大小写字母和数字)
|
||||
function generateRandomString(length = 6) {
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
let result = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += chars[Math.floor(Math.random() * chars.length)];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 生成文件名
|
||||
function generateFileName() {
|
||||
const randomPart = generateRandomString();
|
||||
const timestamp = Date.now(); // 当前时间戳(毫秒级)
|
||||
return `${randomPart}${timestamp}.jpg`;
|
||||
}
|
||||
|
||||
export default generateFileName;
|
||||
|
||||
37
components/postFile.js
Normal file
37
components/postFile.js
Normal file
@@ -0,0 +1,37 @@
|
||||
// let COS = require('cos-wx-sdk-v5')
|
||||
import COS from 'cos-wx-sdk-v5'
|
||||
// const COS = require('./lib/cos-wx-sdk-v5.min.js'); // 上线时使用压缩包
|
||||
const cos = new COS({
|
||||
SecretId: "AKID4KPIyQgjjnkWJzSnwtfHj281tcBZo28v", // 推荐使用环境变量获取;用户的 SecretId,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参考https://cloud.tencent.com/document/product/598/37140
|
||||
SecretKey: "kQvMjuscBWgfSCqeHiGfx3vc7PUP7ctx", // 推荐使用环境变量获取;用户的 SecretKey,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参考https://cloud.tencent.com/document/product/598/37140
|
||||
});
|
||||
|
||||
const uploadFile = function(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
cos.uploadFile({
|
||||
Bucket: 'vv-1317974657', // 填入您自己的存储桶,必须字段
|
||||
Region: 'ap-shanghai', // 存储桶所在地域,例如 ap-beijing,必须字段
|
||||
Key: "headerIcon/" + file.name, // 存储在桶里的对象键(例如1.jpg,a/b/test.txt),必须字段文件名
|
||||
FilePath: file.path, // 必须
|
||||
FileSize: "", // v1.4.3之前的版本必须,v1.4.3及以后的版本非必须
|
||||
SliceSize: 1024 * 1024 * 2, // 触发分块上传的阈值,超过2MB使用分块上传,非必须,按需调整,最小支持1MB
|
||||
// 支持自定义 headers 非必须
|
||||
Headers: {
|
||||
'x-cos-meta-test': 123
|
||||
},
|
||||
}, function(err, data) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(data.Location);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
export default uploadFile
|
||||
|
||||
|
||||
|
||||
|
||||
// https://vv-1317974657.cos.ap-shanghai.myqcloud.com/headerIcon/
|
||||
@@ -3,7 +3,6 @@ export default function request(urldata) {
|
||||
const baseUrl =
|
||||
"http://192.168.0.218:8086/"
|
||||
+ url;
|
||||
console.log("``````````````````````````````````", userInfo);
|
||||
if (userInfo) {
|
||||
uni.getStorage({
|
||||
key: "userinfo",
|
||||
|
||||
Reference in New Issue
Block a user