交接剩余代码
This commit is contained in:
parent
79e179366c
commit
48e5c51ffb
24
src/api/baidu/baidu.js
Normal file
24
src/api/baidu/baidu.js
Normal file
@ -0,0 +1,24 @@
|
||||
import request from '@/utils/request'
|
||||
import { URL } from '@/config'
|
||||
|
||||
/**
|
||||
* 获取百度地图输入点提示词
|
||||
* @author Seven
|
||||
* @data 2025-3-5
|
||||
* @param {
|
||||
* query: value, //关键词
|
||||
* region: this.citys[0], //城市名
|
||||
* city_limit: true, //指定的区域的返回结果
|
||||
* ret_coordtype: "gcj02ll", //坐标类型 1(WGS84ll即GPS经纬度)2(GCJ02ll即国测局经纬度坐标) 3(BD09ll即百度经纬度坐标) 4(BD09mc即百度米制坐标)
|
||||
*}
|
||||
* @returns { query,region }
|
||||
* @see https://mall.gpxscs.cn/mobile/shop/merch/baidu/place/v2/suggestion
|
||||
*/
|
||||
|
||||
export function getBaiduSuggestion(params) {
|
||||
return request({
|
||||
url: URL.baidu.getBaiduSuggestion,
|
||||
method: 'get',
|
||||
params,
|
||||
})
|
||||
}
|
||||
33
src/api/upload.js
Normal file
33
src/api/upload.js
Normal file
@ -0,0 +1,33 @@
|
||||
import request from '@/utils/request'
|
||||
import { URL } from '@/config'
|
||||
|
||||
export function batchNoApi(file, type) {
|
||||
const formData = new FormData()
|
||||
formData.append('upfile', file)
|
||||
formData.append('imgType', type)
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: URL.ocr.batchNoApi,
|
||||
method: 'post',
|
||||
data: formData,
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
.catch((e) => reject(console.warn(e)))
|
||||
})
|
||||
}
|
||||
|
||||
export function imgOcrResultApi(data) {
|
||||
return request({
|
||||
url: URL.ocr.imgOcrResultApi,
|
||||
method: 'POST',
|
||||
data,
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
})
|
||||
}
|
||||
@ -29,6 +29,14 @@ let url = {
|
||||
disableUpdateShopApp:
|
||||
api_url + '/admin/admin/app-market-update/enable-or-disable',
|
||||
},
|
||||
baidu: {
|
||||
getBaiduSuggestion:
|
||||
api_url + '/mobile/shop/merch/baidu/place/v2/suggestion',
|
||||
},
|
||||
ocr: {
|
||||
batchNoApi: api_url + '/mobile/shop/lakala/tk/uploadOcrImg',
|
||||
imgOcrResultApi: api_url + '/mobile/shop/lakala/tk/imgOcrResult',
|
||||
},
|
||||
orderPush: {
|
||||
orderPushTest: api_url + '/mobile/account/login/push/testcase',
|
||||
},
|
||||
|
||||
87
src/utils/file.js
Normal file
87
src/utils/file.js
Normal file
@ -0,0 +1,87 @@
|
||||
export async function compressImage(file, options = {}) {
|
||||
// 提取选项参数,设置默认值
|
||||
const {
|
||||
quality = 0.75,
|
||||
maxWidth = 800,
|
||||
maxHeight = 600
|
||||
} = options;
|
||||
|
||||
// 验证输入是否为有效的File对象
|
||||
if (!(file instanceof File)) {
|
||||
throw new Error('输入参数必须是一个File对象');
|
||||
}
|
||||
|
||||
// 检查文件类型是否为图片
|
||||
if (!file.type.startsWith('image/')) {
|
||||
throw new Error('输入文件必须是图片类型');
|
||||
}
|
||||
|
||||
// 创建一个Promise来处理异步操作
|
||||
return new Promise((resolve, reject) => {
|
||||
// 创建Image对象用于加载图片
|
||||
const img = new Image();
|
||||
|
||||
// 监听图片加载完成事件
|
||||
img.onload = () => {
|
||||
// 创建Canvas元素
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
// 获取原始图片尺寸
|
||||
let width = img.width;
|
||||
let height = img.height;
|
||||
|
||||
// 计算调整后的尺寸(保持原始比例)
|
||||
if (width > maxWidth) {
|
||||
height = height * (maxWidth / width);
|
||||
width = maxWidth;
|
||||
}
|
||||
|
||||
if (height > maxHeight) {
|
||||
width = width * (maxHeight / height);
|
||||
height = maxHeight;
|
||||
}
|
||||
|
||||
// 设置Canvas尺寸
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
|
||||
// 在Canvas上绘制图片
|
||||
ctx.drawImage(img, 0, 0, width, height);
|
||||
|
||||
// 将Canvas内容转换为Blob对象
|
||||
canvas.toBlob(
|
||||
(blob) => {
|
||||
if (!blob) {
|
||||
reject(new Error('图片转换失败'));
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建新的File对象
|
||||
const compressedFile = new File(
|
||||
[blob],
|
||||
file.name,
|
||||
{ type: blob.type, lastModified: Date.now() }
|
||||
);
|
||||
|
||||
resolve(compressedFile);
|
||||
},
|
||||
file.type, // 使用原始图片类型
|
||||
quality // 压缩质量
|
||||
);
|
||||
};
|
||||
|
||||
// 监听图片加载错误事件
|
||||
img.onerror = () => reject(new Error('图片加载失败'));
|
||||
|
||||
// 读取图片数据
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
img.src = reader.result;
|
||||
};
|
||||
reader.onerror = () => reject(new Error('文件读取失败'));
|
||||
|
||||
// 开始读取文件
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user