From 76c766f2d2fe94730186fbb19545c4216cc9891f Mon Sep 17 00:00:00 2001 From: ISFP_T <68358856@qq.com> Date: Fri, 27 Mar 2026 17:38:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=9B=B4=E6=9B=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env/.env.development | 4 +- src/manifest.json | 4 +- .../pages/store-management/index.vue | 4 +- src/utils/upload/alioss.ts | 62 ++++++--------- src/utils/upload/ymx.ts | 75 +++++++------------ 5 files changed, 56 insertions(+), 93 deletions(-) diff --git a/env/.env.development b/env/.env.development index 5a99f98..f403dd5 100644 --- a/env/.env.development +++ b/env/.env.development @@ -5,7 +5,7 @@ VITE_DELETE_CONSOLE=false #本地环境 #VITE_SERVER_BASEURL=http://liuyao.nat100.top/meiguowaimai -VITE_SERVER_BASEURL=http://192.168.5.58:8080 -#VITE_SERVER_BASEURL=https://howhowfresh.com/prod-api +#VITE_SERVER_BASEURL=http://192.168.5.58:8080 +VITE_SERVER_BASEURL=https://howhowfresh.com/prod-api #VITE_SERVER_BASEURL=http://192.168.1.8:8811 #VITE_SERVER_BASEURL=http://mifengchuantou.natapp1.cc/meiguowaimai diff --git a/src/manifest.json b/src/manifest.json index 47f5426..2af68a3 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,8 +2,8 @@ "name" : "CHEFLINK Merchant", "appid" : "__UNI__BB8E3C9", "description" : "美国外卖商户端", - "versionName" : "1.0.17", - "versionCode" : 117, + "versionName" : "1.0.21", + "versionCode" : 121, "transformPx" : false, /* 5+App特有相关 */ "app-plus" : { diff --git a/src/pages-user/pages/store-management/index.vue b/src/pages-user/pages/store-management/index.vue index 14cf297..9d7b4e6 100644 --- a/src/pages-user/pages/store-management/index.vue +++ b/src/pages-user/pages/store-management/index.vue @@ -20,7 +20,7 @@ const formData = ref({ latitude: '', // 商家纬度 businessHours: '', // 营业时间 minOrderPrice: '', // 最小订单金额 - selfPickup: true, // 是否支持自取(1-支持 2-不支持) + selfPickup: false, // 是否支持自取(1-支持 2-不支持) pickupTime: '', // 自取时长(如"30分钟") deliveryService: true, // 是否支持配送(1-支持 2-不支持) deliveryTime: '1', // 配送时长(单位:天,如"1") @@ -495,7 +495,7 @@ function handleClickStatePicker() { - + {{ t('pages-user.store-management.index.isSelfPickup') diff --git a/src/utils/upload/alioss.ts b/src/utils/upload/alioss.ts index bf652f2..1ac0766 100644 --- a/src/utils/upload/alioss.ts +++ b/src/utils/upload/alioss.ts @@ -1,31 +1,13 @@ -import Crypto from 'crypto-js' -import {Base64} from 'js-base64' import {i18n} from "@/locale"; +const UPLOAD_ENDPOINT = '/resource/oss/upload' +const CLIENT_ID = 'e5cd7e4891bf95d1d19206ce24a7b32e' -const env = { - uploadImageUrl: 'https://wendy123.oss-ap-southeast-1.aliyuncs.com/', // 默认存在根目录,可根据需求改 - accessKeySecret: 'TSZOD1jULKPFsNp2zKhAopLe3c3AiH', // accessKeySecret 去你的阿里云上控制台上找 - ossAccessKeyId: 'LTAI5tQq1bSBFCfsbvwX6DqQ', // AccessKeyId 去你的阿里云上控制台上找 - timeout: 87600, // 这个是上传文件时Policy的失效时间 -} - -const getPolicyBase64 = function (): string { - const date = new Date() - date.setHours(date.getHours() + env.timeout) - const expirationTime = date.toISOString() - const policyText = { - expiration: expirationTime, // 设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了 - conditions: [ - ['content-length-range', 0, 2000 * 1024 * 1024], // 设置上传文件的大小限制,2G - ], +function parseUploadResponse(data: any): string { + const parsed = typeof data === 'string' ? JSON.parse(data || '{}') : (data || {}) + if (parsed.code && parsed.code !== 200) { + throw new Error(parsed.msg || 'upload failed') } - - return Base64.encode(JSON.stringify(policyText)) -} - -const getSignature = function (policyBase64: string): string { - const bytes = Crypto.HmacSHA1(policyBase64, env.accessKeySecret) - return Crypto.enc.Base64.stringify(bytes) + return parsed?.data?.url || parsed?.data || parsed?.url || '' } // 上传图片到阿里云oss @@ -35,32 +17,30 @@ const upload = function (filePath: string, suffix = '.png', dir = 'app/image/') return uni.showToast({icon: "none", title: i18n.global.t('common.prompt.picture-wrong-please-try-again')}) } - // 图片名字 可以自行定义,这里是采用当前的时间戳 + 150内的随机数来给图片命名的 - const fileKey = dir + new Date().getTime() + Math.floor(Math.random() * 150) + suffix - - const aliyunServerURL = env.uploadImageUrl // OSS地址,需要https - const policyBase64 = getPolicyBase64() - const signature = getSignature(policyBase64) // 获取签名 - uni.uploadFile({ - url: aliyunServerURL, // 开发者服务器 url + url: UPLOAD_ENDPOINT, filePath: filePath, // 要上传文件资源的路径 name: 'file', // 必须填file timeout: 20000, - formData: { - key: fileKey, - policy: policyBase64, - OSSAccessKeyId: env.ossAccessKeyId, - signature: signature, - success_action_status: '200', + header: { + clientid: CLIENT_ID, }, + formData: {}, success: function (res) { - console.log(res) if (res.statusCode !== 200) { reject(new Error('upload error:' + JSON.stringify(res))) return } - resolve(aliyunServerURL + fileKey) + try { + const uploadedUrl = parseUploadResponse(res.data) + if (!uploadedUrl) { + reject(new Error('upload response url is empty')) + return + } + resolve(uploadedUrl) + } catch (error) { + reject(error) + } }, fail: function (err) { console.log(err) diff --git a/src/utils/upload/ymx.ts b/src/utils/upload/ymx.ts index 02eb909..a0f6240 100644 --- a/src/utils/upload/ymx.ts +++ b/src/utils/upload/ymx.ts @@ -1,34 +1,16 @@ -import CryptoJS from 'crypto-js' -import {Base64} from 'js-base64' import {i18n} from '@/locale' +const baseUrl = import.meta.env.VITE_SERVER_BASEURL -// === 👉 请在这里填写你的 AWS 信息 === -const S3Config = { - bucket: 'cheflink', // 你的存储桶名称 - region: 'us-east-1', // 桶所在区域 - accessKeyId: 'AKIA3LKQVMAPD3KFPJGS', - secretKey: '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', - timeout: 0.1 // 签名有效时间(小时) -} +const UPLOAD_ENDPOINT = '/resource/oss/upload' +const CLIENT_ID = 'e5cd7e4891bf95d1d19206ce24a7b32e' -// === 签名函数 === -function getPolicyBase64(): string { - const expiration = new Date(Date.now() + 10 * 60 * 1000).toISOString() // 10分钟有效 - const policyText = { - expiration, - conditions: [ - {bucket: S3Config.bucket}, - ['starts-with', '$key', 'cheflink/'], - ['starts-with', '$Content-Type', 'image/'] - ] + +function parseUploadResponse(data: any): string { + const parsed = typeof data === 'string' ? JSON.parse(data || '{}') : (data || {}) + if (parsed.code && parsed.code !== 200) { + throw new Error(parsed.msg || 'upload failed') } - return Base64.encode(JSON.stringify(policyText)) -} - - -function getSignature(policyBase64: string): string { - const bytes = CryptoJS.HmacSHA1(policyBase64, S3Config.secretKey) - return CryptoJS.enc.Base64.stringify(bytes) + return parsed?.data?.url || parsed?.data || parsed?.url || '' } // === 图片压缩函数 === @@ -89,7 +71,7 @@ function compressImageIfNeeded(filePath: string, size: number): Promise }) } -// === S3 上传函数 === +// 上传文件到后端接口 const uploadToS3 = async function (filePath: string, suffix = '.jpg', dir = 'cheflink/'): Promise { if (!filePath) { uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.picture-wrong-please-try-again')}) @@ -120,32 +102,33 @@ const uploadToS3 = async function (filePath: string, suffix = '.jpg', dir = 'che return Promise.reject(err) } - // 文件名 - const filename = Date.now() + Math.floor(Math.random() * 1000) + suffix - const key = dir + filename - const policyBase64 = getPolicyBase64() - const signature = getSignature(policyBase64) - const uploadUrl = `https://${S3Config.bucket}.s3.${S3Config.region}.amazonaws.com/` - return new Promise((resolve, reject) => { uni.uploadFile({ - url: uploadUrl, + url:baseUrl+ UPLOAD_ENDPOINT, filePath: uploadPath, name: 'file', - formData: { - key, - AWSAccessKeyId: S3Config.accessKeyId, - policy: policyBase64, - signature, - 'Content-Type': 'image/jpeg', + header: { + clientid: CLIENT_ID, }, + formData: {}, success: res => { - if (res.statusCode === 204) { - uni.showToast({icon: 'none', title: i18n.global.t('common.operation-success')}) - resolve(`${uploadUrl}${key}`) - } else { + if (res.statusCode !== 200) { uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.up-failed')}) reject(new Error(`上传失败,状态码: ${res.statusCode}`)) + return + } + try { + const uploadedUrl = parseUploadResponse(res.data) + if (!uploadedUrl) { + uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.up-failed')}) + reject(new Error('上传失败,返回地址为空')) + return + } + uni.showToast({icon: 'none', title: i18n.global.t('common.operation-success')}) + resolve(uploadedUrl) + } catch (error) { + uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.up-failed')}) + reject(error) } }, fail: err => {