Browse Source

feat(common): 更新 API 地址并添加图片处理功能

- 更新 API 地址和图片域名,切换至本地测试环境
- 新增 img 函数,用于处理图片路径转换
- 新增 getDefaultImage 函数,用于获取默认图片- 修改图片上传逻辑,优化错误处理和用户提示
master
liutong 1 year ago
parent
commit
6e98e71ebe
  1. 8
      common/config.js
  2. 50
      common/util.js
  3. 28
      components/AQ/AQUplodeImgMulti.vue

8
common/config.js

@ -1,10 +1,10 @@
// 线上地址
const Api_url='http://146.56.228.75:20021/api'
const img_domian = 'http://146.56.228.75:20021/'
// const Api_url='http://146.56.228.75:20021/api'
// const img_domian = 'http://146.56.228.75:20021/'
//本地测试地址
// const Api_url='http://zhjw.cc/api'
// const img_domian = 'http://zhjw.cc/'
const Api_url='http://zhjw.cc/api'
const img_domian = 'http://zhjw.cc/'
const IsDemo = false

50
common/util.js

@ -1,3 +1,5 @@
import {img_domian} from "./config";
function formatTime(time) {
if (typeof time !== 'number' || time < 0) {
return time
@ -94,10 +96,56 @@ const hexToRgba = (hex, opacity) => { //16进制颜色转rgba
return "rgba(" + parseInt("0x" + hex.slice(1, 3)) + "," + parseInt("0x" + hex.slice(3, 5)) + "," + parseInt("0x" + hex.slice(5, 7)) + "," + opacity + ")"
}
/**
* 图片路径转换
* @param {String} img_path 图片地址
* @param {Object} params 参数针对商品相册里面的图片区分大中小size: bigmidsmall
*/
function img(img_path, params) {
var path = "";
if (img_path != undefined && img_path != "") {
if (img_path.split(',').length > 1) {
img_path = img_path.split(',')[0];
}
if (params && img_path != getDefaultImage().goods) {
// 过滤默认图
let arr = img_path.split(".");
let suffix = arr[arr.length - 1];
arr.pop();
arr[arr.length - 1] = arr[arr.length - 1] + "_" + params.size.toUpperCase();
arr.push(suffix);
img_path = arr.join(".");
}
if (img_path.indexOf("http://") == -1 && img_path.indexOf("https://") == -1) {
path = img_domian + "/" + img_path;
} else {
path = img_path;
}
if(img_domian.indexOf('https://') != -1){
path = path.replace('http://', 'https://');
}
}
// path += '?t=' + parseInt(new Date().getTime() / 1000);
return path;
}
/**
* 获取默认图
*/
function getDefaultImage() {
let defaultImg = store.state.defaultImg;
defaultImg.goods = img(defaultImg.goods);
defaultImg.head = img(defaultImg.head);
defaultImg.store = img(defaultImg.store);
defaultImg.article = img(defaultImg.article);
return defaultImg;
}
module.exports = {
formatTime,
formatDateTime,
formatLocation,
dateUtils,
hexToRgba
hexToRgba,
img
}

28
components/AQ/AQUplodeImgMulti.vue

@ -145,7 +145,6 @@ import {Api_url} from "../../common/config";
// url: '/pages/student/login/login'
// })
// }
alert(token)
await uni.uploadFile({
url: this.uploadApiUrl, //
@ -160,28 +159,41 @@ import {Api_url} from "../../common/config";
success: (uploadFileRes) => {
let res = JSON.parse(uploadFileRes.data.replace(/\ufeff/g, "") || "{}")
console.log('上传成功1',res);
if (res.code >= 0){
if (res.code == 1){
let _arr = {}
// 3uni-app
_arr.url = res.data.pic_url
_arr.extname = res.data.file_ext
_arr.name = res.data.pic_name
_arr.url = res.data.url
_arr.extname = res.data.ext
_arr.name = res.data.name
console.log('xxx',_arr)
this.fileList.push(_arr)
console.log('上传成功2',_arr);
this.filePathArr.push(res.data.pic_path)
this.filePathArr.push(res.data.path)
//
this.emitUploadSuccess(this.filePathArr)
}else{
//
uni.showToast({
title: res.message
title: res.msg,
icon: 'none'
})
if(res.code == 401){
//1s
setTimeout(() => {
uni.navigateTo({
url: '/pages/student/login/login'
})
}, 1000);
}
}
},
fail: (err) => {
//
uni.showToast({
title: err.message
title: err.msg,
icon: 'none'
})
}
})

Loading…
Cancel
Save