tmp: 部分代码与UnishopV5结合,但是代码有严重缺陷

This commit is contained in:
2025-12-20 15:30:39 +08:00
parent ed5181b382
commit e263a616f6
183 changed files with 31316 additions and 18590 deletions

View File

@@ -8,15 +8,15 @@ import {
export default {
/**
* 页面跳转
* @param {string} to 跳转链接 /pages/idnex/index
* @param {string} to 跳转链接 /pages/index/index
* @param {Object} param 参数 {key : value, ...}
* @param {string} mode 模式
*/
redirectTo(to, param, mode) {
let url = to;
let tabbarList = ['/pages/index/index', '/pages/goods/category', '/pages/vr/index', '/pages/contact/contact', '/pages/member/index'];
let tabbarList = ['/pages/index/index', '/pages/goods/category', '/pages/goods/cart', '/pages/member/index'];
if (param != undefined) {
Object.keys(param).forEach(function (key) {
Object.keys(param).forEach(function(key) {
if (url.indexOf('?') != -1) {
url += "&" + key + "=" + param[key];
} else {
@@ -26,6 +26,8 @@ export default {
}
for (let i = 0; i < tabbarList.length; i++) {
if (url.indexOf(tabbarList[i]) == 0) {
if(url.split('?')[1]) uni.setStorageSync('tabBarParams',url.split('?')[1]);
else uni.removeStorageSync('tabBarParams')
uni.switchTab({
url
});
@@ -64,8 +66,6 @@ export default {
* @param {Object} params 参数针对商品、相册里面的图片区分大中小size: big、mid、small
*/
img(img_path, params) {
var path = "";
if (img_path != undefined && img_path != "") {
if (img_path.split(',').length > 1) {
@@ -78,19 +78,17 @@ export default {
arr.pop();
arr[arr.length - 1] = arr[arr.length - 1] + "_" + params.size.toUpperCase();
arr.push(suffix);
// if(img_path.indexOf('attachment') == -1){
// img_path = arr.join(".");
// }
img_path = arr.join(".");
}
if (img_path.indexOf("http://") == -1 && img_path.indexOf("https://") == -1) {
path = Config.imgDomain + "/" + img_path;
} else {
// console.log(img_path)
path = img_path;
}
if (Config.h5Domain.indexOf('https://') != -1) {
path = path.replace('http://', 'https://');
}
}
// path += '?t=' + parseInt(new Date().getTime() / 1000);
return path;
},
@@ -98,7 +96,7 @@ export default {
* 时间戳转日期格式
* @param {Object} timeStamp
*/
timeStampTurnTime(timeStamp, type = "") {
timeStampTurnTime(timeStamp, format = "Y-m-d H:i:s") {
if (timeStamp != undefined && timeStamp != "" && timeStamp > 0) {
var date = new Date();
date.setTime(timeStamp * 1000);
@@ -113,14 +111,15 @@ export default {
var second = date.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute;
second = second < 10 ? ('0' + second) : second;
if (type) {
if (type == 'yearMonthDay') {
return y + '年' + m + '' + d + '日';
}
return y + '-' + m + '-' + d;
} else {
return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
}
format = format.replace('Y', y);
format = format.replace('m', m);
format = format.replace('d', d);
format = format.replace('H', h);
format = format.replace('i', minute);
format = format.replace('s', second);
return format;
} else {
return "";
}
@@ -187,19 +186,19 @@ export default {
* @param {Object} elem
* @param {Object} arr
*/
inArray: function (elem, arr) {
inArray: function(elem, arr) {
return arr == null ? -1 : arr.indexOf(elem);
},
/**
* 获取某天日期
* @param {Object} day
*/
getDay: function (day) {
getDay: function(day) {
var today = new Date();
var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
today.setTime(targetday_milliseconds);
const doHandleMonth = function (month) {
const doHandleMonth = function(month) {
var m = month;
if (month.toString().length == 1) {
m = "0" + month;
@@ -231,7 +230,7 @@ export default {
* @param callback
* @param url
*/
upload: function (num, params, callback, url) {
upload: function(num, params, callback, url) {
// #ifdef H5
var app_type = this.isWeiXin() ? 'wechat' : 'h5';
var app_type_name = this.isWeiXin() ? '微信公众号' : 'H5';
@@ -275,7 +274,7 @@ export default {
count: imgs_num,
sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册或者拍照
success: async function (res) {
success: async (res) => {
const tempFilePaths = res.tempFilePaths;
var _data = data;
var imgs = [];
@@ -283,9 +282,16 @@ export default {
title: '图片上传中'
})
for (var i = 0; i < tempFilePaths.length; i++) {
var path = await _self.upload_file_server(tempFilePaths[i], _data, params.path,
url);
imgs.push(path);
try {
var path = await _self.upload_file_server(tempFilePaths[i], _data, params.path,
url);
imgs.push(path);
} catch (e) {
this.showToast({
title: e,
});
break;
}
if (imgs.length == tempFilePaths.length) {
uni.hideLoading()
uni.showToast({
@@ -297,11 +303,12 @@ export default {
}
},
fail: err => {
uni.hideLoading()
uni.showToast({
title: '上传失败',
icon: 'none'
})
if (err.errMsg != 'chooseImage:fail cancel') {
uni.showToast({
title: '上传失败',
icon: 'none'
})
}
}
});
},
@@ -319,13 +326,25 @@ export default {
name: 'file',
fileType: data.fileType || 'image',
formData: data,
success: function (res) {
success: (res) => {
var path_str = JSON.parse(res.data);
if (path_str.code >= 0) {
resolve(path_str.data.pic_path);
typeof callback == 'function' && callback(path_str.data.pic_path);
} else {
reject("error");
reject(path_str.message);
}
uni.hideLoading();
},
fail: (res) => {
if (res.statusCode != 200) {
reject(res.errMsg || '上传错误');
uni.hideLoading();
}
},
complete: (res) => {
if (res.statusCode != 200) {
reject('服务器发生错误');
uni.hideLoading();
}
}
});
@@ -395,7 +414,7 @@ export default {
* 检测苹果X以上的手机
*/
isIPhoneX() {
let res = uni.getSystemInfoSync();
let res = uni.getDeviceInfo();
if (res.model.search('iPhone X') != -1) {
return true;
}
@@ -403,7 +422,7 @@ export default {
},
//判断安卓还是iOS
isAndroid() {
let platform = uni.getSystemInfoSync().platform
let platform = uni.getDeviceInfo().platform
if (platform == 'ios') {
return false;
} else if (platform == 'android') {
@@ -415,7 +434,7 @@ export default {
* @param {Object} obj
*/
deepClone(obj) {
const isObject = function (obj) {
const isObject = function(obj) {
return typeof obj == 'object';
}
@@ -431,7 +450,6 @@ export default {
}
return cloneObj
},
/**
* 打开微信企业客服
* @param {Function} fallbackFunc 降级处理函数
@@ -464,11 +482,11 @@ export default {
* @param {Object} link
*/
diyRedirectTo(link) {
//if (link == null || Object.keys(link).length == 1) return;
if (link == null || Object.keys(link).length == 1) return;
// 外部链接
if (link.wap_url && link.wap_url.indexOf('http') != -1 || link.wap_url && link.wap_url.indexOf('http') != -1) {
if (link.wap_url && link.wap_url.indexOf('http') != -1 || link.wap_url && link.wap_url.indexOf('https') != -1) {
// #ifdef H5
window.location.href = link.wap_url;
// #endif
@@ -492,10 +510,8 @@ export default {
uni.makePhoneCall({
phoneNumber: link.mobile,
success: (res) => {
},
fail: (res) => {
}
success: (res) => {},
fail: (res) => {}
});
} else if (link.name == 'MEMBER_CONTACT') {
@@ -585,9 +601,12 @@ export default {
*/
uniappIsIPhoneX() {
let isIphoneX = false;
let systemInfo = uni.getSystemInfoSync();
let deviceInfo = uni.getDeviceInfo();
let windowInfo = uni.getWindowInfo();
// #ifdef MP
if (systemInfo.model.search('iPhone X') != -1 || systemInfo.model.search('iPhone 11') != -1 || systemInfo.model.search('iPhone 12') != -1 || systemInfo.model.search('iPhone 13') != -1) {
if (deviceInfo.model.search('iPhone X') != -1 || deviceInfo.model.search('iPhone 11') != -1 || deviceInfo.model
.search('iPhone 12') != -1 || deviceInfo.model.search('iPhone 13') != -1 || parseInt(deviceInfo.model.split(
'iPhone')[1]) > 13) {
isIphoneX = true;
}
// #endif
@@ -596,11 +615,11 @@ export default {
var u = navigator.userAgent;
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if (isIOS) {
if (systemInfo.screenWidth == 375 && systemInfo.screenHeight == 812 && systemInfo.pixelRatio == 3) {
if (windowInfo.screenWidth == 375 && windowInfo.screenHeight == 812 && deviceInfo.pixelRatio == 3) {
isIphoneX = true;
} else if (systemInfo.screenWidth == 414 && systemInfo.screenHeight == 896 && systemInfo.pixelRatio == 3) {
} else if (windowInfo.screenWidth == 414 && windowInfo.screenHeight == 896 && deviceInfo.pixelRatio == 3) {
isIphoneX = true;
} else if (systemInfo.screenWidth == 414 && systemInfo.screenHeight == 896 && systemInfo.pixelRatio == 2) {
} else if (windowInfo.screenWidth == 414 && windowInfo.screenHeight == 896 && deviceInfo.pixelRatio == 2) {
isIphoneX = true;
}
}
@@ -612,9 +631,9 @@ export default {
*/
uniappIsIPhone11() {
let isIphone11 = false;
let systemInfo = uni.getSystemInfoSync();
let deviceInfo = uni.getDeviceInfo();
// #ifdef MP
if (systemInfo.model.search('iPhone 11') != -1) {
if (deviceInfo.model.search('iPhone 11') != -1) {
isIphone11 = true;
}
// #endif
@@ -623,7 +642,6 @@ export default {
// #ifdef H5
//判断该浏览器是否为safaria浏览器
isSafari() {
let res = uni.getSystemInfoSync();
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('applewebkit') > -1 && ua.indexOf('mobile') > -1 && ua.indexOf('safari') > -1 &&
ua.indexOf('linux') === -1 && ua.indexOf('android') === -1 && ua.indexOf('chrome') === -1 &&
@@ -670,7 +688,6 @@ export default {
}
},
/**
*
* @param val 转化时间字符串 (转化时分秒)
* @returns {string}
*/
@@ -689,7 +706,7 @@ export default {
* 获取定位信息
*/
getLocation(param = {}) {
/*uni.getLocation({
uni.getLocation({
type: param.type ?? 'gcj02',
success: res => {
store.commit('setLocation', res);
@@ -701,7 +718,7 @@ export default {
complete: res => {
typeof param.complete == 'function' && param.complete(res);
}
});*/
});
},
// 计算两个经纬度之间的距离
getDistance(lat1, lng1, lat2, lng2) {
@@ -709,8 +726,8 @@ export default {
var radLat2 = lat2 * Math.PI / 180.0;
var a = radLat1 - radLat2;
var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(
Math.sin(b / 2), 2)));
s = s * 6378.137; // EARTH_RADIUS;
s = Math.round(s * 10000) / 10000;
return s;
@@ -737,7 +754,7 @@ export default {
/**
* 微信订阅消息
*/
subscribeMessage(keywords) {
subscribeMessage(keywords, callback) {
// #ifdef MP-WEIXIN
let url = '/weapp/api/weapp/messagetmplids';
// #endif
@@ -759,6 +776,9 @@ export default {
},
fail: (res) => {
console.log('fail', res)
},
complete: (res) => {
typeof callback == 'function' && callback();
}
})
// #endif
@@ -771,10 +791,18 @@ export default {
},
fail: res => {
console.log('fail', res)
},
complete: (res) => {
typeof callback == 'function' && callback();
}
});
// #endif
} else {
typeof callback == 'function' && callback();
}
},
fail: res => {
typeof callback == 'function' && callback();
}
})
},
@@ -807,10 +835,8 @@ export default {
title: shareConfig.title,
path: shareConfig.path,
imageUrl: shareConfig.imageUrl,
success: res => {
},
fail: res => {
}
success: res => {},
fail: res => {}
}
//分享到朋友圈
let query = '';
@@ -846,8 +872,7 @@ export default {
Http.sendRequest({
url: '/wechat/api/wechat/jssdkconfig',
data: {
url: uni.getSystemInfoSync().platform == 'ios' ? uni.getStorageSync('initUrl') : window.location
.href
url: uni.getDeviceInfo().platform == 'ios' ? uni.getStorageSync('initUrl') : window.location.href
},
success: res => {
if (res.code == 0) {
@@ -870,7 +895,7 @@ export default {
//获取当前路由
getCurrentRoute() {
let currentRoutes = getCurrentPages(); // 获取当前打开过的页面路由数组
let currentRoute = currentRoutes[currentRoutes.length - 1].route //获取当前页面路由
let currentRoute = currentRoutes[currentRoutes.length - 1].route; //获取当前页面路由
let currentParam = currentRoutes[currentRoutes.length - 1].options; //获取路由参数
// 拼接参数
let param = [];
@@ -950,12 +975,10 @@ export default {
var points_D = [];
var points_E = [];
const DIST_AB = Math.sqrt(Math.pow(points[1]['x'] - points[0]['x'], 2) + Math.pow(points[1]['y'] - points[0][
'y'
], 2));
'y'], 2));
// 邻控制BC点间距
const DIST_BC = Math.sqrt(Math.pow(points[2]['x'] - points[1]['x'], 2) + Math.pow(points[2]['y'] - points[1][
'y'
], 2));
'y'], 2));
// D每次在AB方向上移动的距离
if (points[0]['x'] > points[2]['x']) {
var EACH_MOVE_AD = -(DIST_AB / times);
@@ -1017,5 +1040,157 @@ export default {
verifyMobile(mobile) {
var parse = /^\d{11}$/.test(mobile);
return parse;
},
// 获取缓存key
getStorageKey(key) {
return Config.storagePrefix + key;
},
// 重写uni缓存方法
rewriteUniStorageMethod() {
const setStorageSync = uni.setStorageSync;
const setStorage = uni.setStorage;
const getStorage = uni.getStorage;
const getStorageSync = uni.getStorageSync;
const removeStorage = uni.removeStorage;
const removeStorageSync = uni.removeStorageSync;
uni.setStorage = (options) => {
options.key = this.getStorageKey(options.key);
setStorage(options)
};
uni.setStorageSync = (key, data) => {
setStorageSync(this.getStorageKey(key), data)
};
uni.getStorage = (options) => {
options.key = this.getStorageKey(options.key);
getStorage(options)
};
uni.getStorageSync = (key) => {
return getStorageSync(this.getStorageKey(key))
};
uni.removeStorage = (options) => {
options.key = this.getStorageKey(options.key);
removeStorage(options)
};
uni.removeStorageSync = (key) => {
return removeStorageSync(this.getStorageKey(key))
}
},
//生成唯一id
generateUUID() {
var d = new Date().getTime(); //Timestamp
var d2 = (performance && performance.now && (performance.now() * 1000)) ||
0; //Time in microseconds since page-load or 0 if unsupported
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16; //random number between 0 and 16
if (d > 0) { //Use timestamp until depleted
r = (d + r) % 16 | 0;
d = Math.floor(d / 16);
} else { //Use microseconds since page-load if supported
r = (d2 + r) % 16 | 0;
d2 = Math.floor(d2 / 16);
}
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
},
// 获取弹新人礼弹框页面
openRegisterRewardPath(back) {
return uni.getStorageSync('initiateLogin') || back;
},
// 登录完成后返回页面
loginComplete(back, mode) {
let url = uni.getStorageSync('initiateLogin') || back;
uni.removeStorageSync('initiateLogin')
let jump = true;
let arr = getCurrentPages().reverse();
for (let i = 0; i < arr.length; i++) {
if (url.indexOf(arr[i].route) != -1) {
jump = false;
uni.navigateBack({
delta: i
});
break;
}
}
if (jump) {
this.redirectTo(url, {}, 'redirectTo')
}
},
// 微信提现收款
merchantTransfer(data,withdrawInfo,callback) {
Http.sendRequest({
url: '/wechatpay/api/transfer/transfer',
data: data,
success: res => {
if (res.code == 0) {
uni.hideLoading();
// #ifdef MP-WEIXIN
if (wx.canIUse('requestMerchantTransfer')) {
wx.requestMerchantTransfer({
mchId: withdrawInfo.mch_id,
appId: withdrawInfo.app_id,
package: res.data.package_info,
success: (res) => {
typeof callback == 'function' && callback(res);
},
fail: (res) => {
typeof callback == 'function' && callback(res);
},
});
} else {
wx.showModal({
content: '你的微信版本过低,请更新至最新版本。',
showCancel: false,
});
}
// #endif
// #ifdef H5
if (this.isWeiXin()) {
if (uni.getDeviceInfo().platform == 'ios') {
var url = uni.getStorageSync('initUrl');
} else {
var url = location.href;
}
// 获取jssdk配置
Http.sendRequest({
url: '/wechat/api/wechat/jssdkconfig',
data: {
url: url
},
success: jssdkRes => {
var wxJS = new Weixin();
wxJS.init(jssdkRes.data);
wxJS.withdrawWechat({
mch_id: withdrawInfo.mch_id,
wechat_appid: withdrawInfo.app_id,
package_info: res.data.package_info
},
res => {
typeof callback == 'function' && callback(res);
},
);
}
})
}
// #endif
} else {
this.showToast({
title: res.message,
});
}
},
fail: err => {
this.showToast({
title: err.message,
});
}
})
}
}