初始化仓库

This commit is contained in:
wangxiaowei
2026-04-14 16:54:04 +08:00
commit 967c25b397
553 changed files with 106514 additions and 0 deletions

1
utils/area.js Normal file

File diff suppressed because one or more lines are too long

58
utils/cache.js Normal file
View File

@ -0,0 +1,58 @@
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
const Cache = {
//设置缓存(expire为缓存时效)
set(key, value, expire) {
let data = {
expire: expire ? (this.time() + expire) : "",
value
}
if (typeof data === 'object')
data = JSON.stringify(data);
try {
uni.setStorageSync(key, data)
} catch (e) {
return false;
}
},
get(key) {
try {
let data = uni.getStorageSync(key)
const {value, expire} = JSON.parse(data)
if(expire && expire < this.time()) {
uni.removeStorageSync(key)
return false;
}else {
return value
}
} catch (e) {
return false;
}
},
//获取当前时间
time() {
return Math.round(new Date() / 1000);
},
remove(key) {
if(key) uni.removeStorageSync(key)
}
}
export default Cache;

89
utils/date.js Normal file
View File

@ -0,0 +1,89 @@
const weekArr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
/**
* @description 时间格式化
* @param dateTime { number } 时间错
* @param fmt { string } 时间格式
* @return { string }
*/
// yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合
export const timeFormat = (dateTime, fmt = 'yyyy-mm-dd') => {
// 如果为null,则格式化当前时间
if (!dateTime) dateTime = Number(new Date());
// 如果dateTime长度为10或者13则为秒和毫秒的时间戳如果超过13位则为其他的时间格式
if (dateTime.toString().length == 10) dateTime *= 1000;
let date = new Date(dateTime);
let ret;
let opt = {
'y+': date.getFullYear().toString(), // 年
'm+': (date.getMonth() + 1).toString(), // 月
'd+': date.getDate().toString(), // 日
'h+': date.getHours().toString(), // 时
'M+': date.getMinutes().toString(), // 分
's+': date.getSeconds().toString() // 秒
};
for (let k in opt) {
ret = new RegExp('(' + k + ')').exec(fmt);
if (ret) {
fmt = fmt.replace(ret[1], ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0'));
}
}
return fmt;
}
/**
* @description 聊天记录专用时间格式化
* @param dateTime { number } 时间错
* @return { string }
*/
export const timeFormatChat = (dateTime) => {
if (dateTime.toString().length == 10) dateTime *= 1000;
let date = new Date(dateTime);
let fmt = timeFormat(dateTime, 'yyyy年mm月dd日 hh:MM')
if (isToday(date)) {
fmt = timeFormat(dateTime, 'hh:MM')
} else if (isThisWeak(date)) {
fmt = weekArr[date.getDay()] + timeFormat(dateTime, ' hh:MM')
} else if (isThisYear(date)) {
fmt = timeFormat(dateTime, 'mm月dd日 hh:MM')
}
return fmt
}
// 是否是今年
const isThisYear = (date) => {
const now = new Date()
return date.getYear() == now.getYear()
}
// 是否是今月
const isThisMonth = (date) => {
const now = new Date()
return isThisYear(date) && date.getMonth() == now.getMonth()
}
// 是否是今天
const isToday = (date) => {
const now = new Date()
return isThisMonth(date) && date.getDate() == now.getDate()
}
// 是否本周
const isThisWeak = (date) => {
const now = new Date()
if (isThisMonth(date)) {
if (now.getDay() - date.getDay() > 0 && now.getDate() - date.getDate() < 7) {
return true
}
} else {
return false
}
}

76
utils/emoji.js Normal file
View File

@ -0,0 +1,76 @@
export default [
'em-smile',
'em-laughing',
'em-blush',
'em-smiley',
'em-relaxed',
'em-smirk',
'em-heart_eyes',
'em-kissing_heart',
'em-kissing_closed_eyes',
'em-flushed',
'em-relieved',
'em-satisfied',
'em-grin',
'em-wink',
'em-stuck_out_tongue_winking_eye',
'em-stuck_out_tongue_closed_eyes',
'em-grinning',
'em-kissing',
'em-kissing_smiling_eyes',
'em-stuck_out_tongue',
'em-sleeping',
'em-worried',
'em-frowning',
'em-anguished',
'em-open_mouth',
'em-grimacing',
'em-confused',
'em-hushed',
'em-expressionless',
'em-unamused',
'em-sweat_smile',
'em-sweat',
'em-disappointed_relieved',
'em-weary',
'em-pensive',
'em-disappointed',
'em-confounded',
'em-fearful',
'em-cold_sweat',
'em-persevere',
'em-cry',
'em-sob',
'em-joy',
'em-astonished',
'em-scream',
'em-tired_face',
'em-angry',
'em-rage',
'em-triumph',
'em-sleepy',
'em-yum',
'em-mask',
'em-dizzy_face',
'em-sunglasses',
'em-imp',
'em-smiling_imp',
'em-neutral_face',
'em-no_mouth',
'em-innocent',
'em-alien',
'em-heart',
'em-broken_heart',
'em-hankey',
'em-thumbsup',
'em-thumbsdown',
'em-ok_hand',
'em-facepunch',
'em-fist',
'em-v',
'em-point_up',
'em-point_down',
'em-point_left',
'em-point_right',
'em-pray'
];

110
utils/login.js Normal file
View File

@ -0,0 +1,110 @@
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
import {
silentLogin
} from '@/api/app';
import {
isWeixinClient,
currentPage,
trottle
} from './tools'
import store from '@/store'
import Cache from './cache'
import {
BACK_URL,
INVITE_CODE
} from '@/config/cachekey'
import {bindSuperior} from '@/api/user'
import wechath5 from './wechath5'
import {router} from '@/router'
// 获取登录凭证code
export function getWxCode() {
return new Promise((resolve, reject) => {
uni.login({
success(res) {
resolve(res.code);
},
fail(res) {
reject(res);
}
});
});
}
//小程序获取用户信息
export function getUserProfile() {
return new Promise((resolve, reject) => {
uni.getUserProfile({
desc: '获取用户信息,完善用户资料 ',
success: (res) => {
resolve(res);
},
fail(res) {}
})
})
}
//小程序静默授权
export async function wxMnpLogin() {
const code = await getWxCode()
const {
code: loginCode,
data: loginData
} = await silentLogin({
code
})
const {
options,
onLoad,
onShow,
route
} = currentPage()
if (loginCode != 1) return
if (loginData.token && !loginData.is_new_user) {
store.commit('login', loginData)
// 绑定邀请码
const inviteCode = Cache.get(INVITE_CODE)
if (inviteCode) {
bindSuperior({code: inviteCode})
Cache.remove(INVITE_CODE)
}
// 刷新页面
onLoad && onLoad(options)
onShow && onShow()
}
}
export const toLogin = trottle(_toLogin, 1000)
function _toLogin() {
//#ifdef MP-WEIXIN
wxMnpLogin()
// #endif
//#ifndef MP-WEIXIN
const {currentRoute} = router
if(currentRoute.meta.auth) {
router.push('/pages/login/login')
}
// #endif
}

125
utils/pay.js Normal file
View File

@ -0,0 +1,125 @@
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
import wechath5 from './wechath5'
import { currentPage, isWeixinClient } from './tools'
export function wxpay(opt) {
//#ifdef H5
if (isWeixinClient()) {
return wechath5.wxPay(opt)
} else {
console.log(opt)
location.href = opt
}
// #endif
//#ifndef H5
return new Promise((resolve, reject) => {
// #ifdef MP-WEIXIN
const params = {
timeStamp: opt.timeStamp,
// 支付签名时间戳注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
nonceStr: opt.nonceStr,
// 支付签名随机串,不长于 32 位
package: opt.package,
// 统一支付接口返回的prepay_id参数值提交格式如prepay_id=***
signType: opt.signType,
// 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
paySign: opt.paySign
}
// #endif
// #ifdef APP-PLUS
const params = {
orderInfo: opt
}
// #endif
console.log(params)
uni.requestPayment({
provider: 'wxpay',
...params,
success: (res) => {
resolve('success')
},
cancel: (res) => {
resolve('fail')
},
fail: (res) => {
resolve('fail')
}
})
})
// #endif
}
export function alipay(opt, pay_way, params, token) {
// #ifdef MP-WEIXIN
uni.$emit('Alipay')
// #endif
//#ifdef H5
if (pay_way == '66') {
//汇付斗拱支付
location.href = opt
} else {
// var ua = navigator.userAgent.toLowerCase()
// if (ua.match(/MicroMessenger/i) == 'micromessenger') {
// uni.navigateTo({
// url: `/bundle/pages/toAlipay/toAlipay?id=${params.order_id}&from=${params.from}&pay_way=${params.pay_way}&key=${token}`
// })
// } else {
const div = document.createElement('div')
// console.log(opt)
/* 此处form就是后台返回接收到的数据 */
div.innerHTML = opt
document.body.appendChild(div)
document.forms[0].submit()
// }
}
// #endif
// #ifdef APP-PLUS
if (pay_way == '66') {
//汇付斗拱支付
plus.runtime.openURL(opt)
} else {
return new Promise((resolve, reject) => {
const params = {
orderInfo: opt
}
console.log(params)
uni.requestPayment({
provider: 'alipay',
...params,
success: (res) => {
resolve('success')
},
cancel: (res) => {
console.log(res)
resolve('fail')
},
fail: (res) => {
console.log(res)
resolve('fail')
}
})
})
}
// #endif
}

109
utils/request.js Normal file
View File

@ -0,0 +1,109 @@
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
import axios from '../js_sdk/xtshadow-axios/axios.min'
import store from '../store'
import { paramsToStr, currentPage, toast } from './tools'
import Cache from './cache'
import { TOKEN } from '../config/cachekey'
import { baseURL } from '../config/app'
import { toLogin } from './login'
import { router } from '../router'
let index = 0
function checkParams(params) {
if (typeof params != 'object') return params
for (let key in params) {
const value = params[key]
if (value === null || value === undefined || value === '') {
delete params[key]
}
}
return params
}
const service = axios.create({
baseURL: baseURL + '/api/',
timeout: 10000,
header: {
'content-type': 'application/json'
}
})
// request拦截器
service.interceptors.request.use(
(config) => {
config.data = checkParams(config.data)
config.params = checkParams(config.params)
if (config.method == 'GET') {
config.url += paramsToStr(config.params)
}
config.header.token = config.header.token || store.getters.token
return config
},
(error) => {
// Do something with request error
console.log(error) // for debug
Promise.reject(error)
}
)
// response 拦截器
service.interceptors.response.use(
async (response) => {
if (response.data) {
const { code, show, msg } = response.data
if (code == 0 && show) {
toast({
title: msg
})
} else if (code == 1 && show) {
toast({
title: msg
})
} else if (code == -1) {
store.commit('logout')
toLogin()
} else if (code == 301) {
// 返回上一页
toast(
{
title: msg
},
{
tab: 3,
url: 1
}
)
}
}
return Promise.resolve(response.data)
},
(error) => {
uni.showToast({
title: '系统错误',
icon: 'none'
})
console.log(error)
console.log('err' + error) // for debug
return Promise.reject(error)
}
)
export default service

137
utils/socket.js Normal file
View File

@ -0,0 +1,137 @@
//
import {
paramsToStr
} from './tools'
class Socket {
constructor(url, data) {
this.connected = false
this.error = false
this.url = `${url}${paramsToStr(data)}`
this.socketTask = {}
this.reconnectLock = true
this.reconnectTimeout = null
this.reconnectNums = 0
// 心跳
this.timeout = 10000
this.clientTimeout = null
this.serverTimeout = null
}
// 允许的订阅
events = {
connect: null,
close: null,
message: null,
error: null,
open: null
}
// 添加订阅
addEvent(type, callback) {
this.events[type] = callback
}
// 触发订阅
dispatch(type, data) {
const fun = this.events[type]
fun && fun(data)
}
connect() {
// 已经连接则无需重复连接
if (this.connected) return
this.dispatch('connect')
this.socketTask = uni.connectSocket({
url: this.url,
complete: () => {}
})
this.socketTask.onOpen(this.onOpen.bind(this))
this.socketTask.onError(this.onError.bind(this));
this.socketTask.onMessage(this.onMessage.bind(this))
this.socketTask.onClose(this.onClose.bind(this));
}
close() {
this.reconnectLock = false
clearTimeout(this.clientTimeout)
clearTimeout(this.serverTimeout)
this.socketTask.close && this.socketTask.close()
}
reconnect() {
if (!this.reconnectLock) {
return
}
// 重连次数过多,断开不重连
if (this.reconnectNums >= 5) {
return
}
this.reconnectNums++
this.reconnectLock = false
// 延迟重连请求过多
clearTimeout(this.reconnectTimeout)
this.reconnectTimeout = setTimeout(() => {
this.connect()
this.reconnectLock = true
}, 4000)
}
start() {
clearTimeout(this.clientTimeout)
clearTimeout(this.serverTimeout)
this.clientTimeout = setTimeout(() => {
this.send({
event: 'ping'
})
this.serverTimeout = setTimeout(() => {
this.socketTask.close()
}, this.timeout)
}, this.timeout)
}
reset() {
this.reconnectNums = 0
this.start()
}
send(data) {
// 如果socket已连接则发送消息
if (!this.connected) {
return
}
let datas = JSON.stringify(data)
// console.log('发送信息:' + datas)
this.socketTask.send({
data: datas,
})
}
onOpen() {
this.connected = true
// 开启心跳
this.start()
// console.log('连接成功')
this.dispatch('open')
}
onError(res) {
this.error = true
this.connected = false
this.dispatch('error')
// console.log('连接错误', res)
}
onMessage({data}) {
this.dispatch('message', JSON.parse(data))
// console.log('收到信息:', data)
// 重置心跳
this.reset()
}
onClose(res) {
this.dispatch('close')
// console.log('连接已关闭', res)
this.connected = false
this.reconnect()
}
}
export default Socket

439
utils/tools.js Normal file
View File

@ -0,0 +1,439 @@
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
import { loadingType } from "./type";
import { baseURL } from "@/config/app.js";
import store from "@/store";
//所在环境
let client = null;
// #ifdef MP-WEIXIN
client = 1;
// #endif
// #ifdef H5
client = isWeixinClient() ? 2 : 6;
// #endif
// #ifdef APP-PLUS
client = 3;
uni.getSystemInfo({
success: (res) => {
client = res.platform == "ios" ? 3 : 4;
},
fail: (res) => {
client = 3;
},
});
// #endif
export { client };
//节流
export const trottle = (func, time = 1000, context) => {
let previous = new Date(0).getTime();
return function (...args) {
let now = new Date().getTime();
if (now - previous > time) {
func.apply(context, args);
previous = now;
}
};
};
//节流
export const debounce = (func, time = 1000, context) => {
let timer = null;
return function (...args) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
timer = null;
func.apply(context, args);
}, time);
};
};
//判断是否为微信环境
export function isWeixinClient() {
// #ifdef H5
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
//这是微信环境
return true;
} else {
//这是非微信环境
return false;
}
// #endif
// #ifndef H5
return false;
// #endif
}
//判断是否为安卓环境
export function isAndroid() {
let u = navigator.userAgent;
return u.indexOf("Android") > -1 || u.indexOf("Adr") > -1;
}
//获取url后的参数 以对象返回
export function strToParams(str) {
var newparams = {};
for (let item of str.split("&")) {
newparams[item.split("=")[0]] = item.split("=")[1];
}
return newparams;
}
//重写encodeURL函数
export function urlencode(str) {
str = (str + "").toString();
return encodeURIComponent(str)
.replace(/!/g, "%21")
.replace(/'/g, "%27")
.replace(/\(/g, "%28")
.replace(/\)/g, "%29")
.replace(/\*/g, "%2A")
.replace(/%20/g, "+");
}
//一维数组截取为二维数组
export function arraySlice(data, array = [], optNum = 10) {
data = JSON.parse(JSON.stringify(data));
if (data.length <= optNum) {
data.length > 0 && array.push(data);
return array;
}
array.push(data.splice(0, optNum));
return arraySlice(data, array, optNum);
}
//对象参数转为以?&拼接的字符
export function paramsToStr(params) {
let p = "";
if (typeof params == "object") {
p = "?";
for (let props in params) {
p += `${props}=${params[props]}&`;
}
p = p.slice(0, -1);
}
return p;
}
// 获取wxml元素
export function getRect(selector, all, context) {
return new Promise(function (resolve) {
let qurey = uni.createSelectorQuery();
if (context) {
qurey = uni.createSelectorQuery().in(context);
}
qurey[all ? "selectAll" : "select"](selector)
.boundingClientRect(function (rect) {
if (all && Array.isArray(rect) && rect.length) {
resolve(rect);
}
if (!all && rect) {
resolve(rect);
}
})
.exec();
});
}
// 轻提示
export function toast(info = {}, navigateOpt) {
let title = info.title || "";
let icon = info.icon || "none";
let endtime = info.endtime || 2000;
if (title)
uni.showToast({
title: title,
icon: icon,
duration: endtime,
});
if (navigateOpt != undefined) {
if (typeof navigateOpt == "object") {
let tab = navigateOpt.tab || 1,
url = navigateOpt.url || "";
switch (tab) {
case 1:
//跳转至 table
setTimeout(function () {
uni.switchTab({
url: url,
});
}, endtime);
break;
case 2:
//跳转至非table页面
setTimeout(function () {
uni.navigateTo({
url: url,
});
}, endtime);
break;
case 3:
//返回上页面
setTimeout(function () {
uni.navigateBack({
delta: parseInt(url),
});
}, endtime);
break;
case 4:
//关闭当前所有页面跳转至非table页面
setTimeout(function () {
uni.reLaunch({
url: url,
});
}, endtime);
break;
case 5:
//关闭当前页面跳转至非table页面
setTimeout(function () {
uni.redirectTo({
url: url,
});
}, endtime);
break;
}
} else if (typeof navigateOpt == "function") {
setTimeout(function () {
navigateOpt && navigateOpt();
}, endtime);
}
}
}
//菜单跳转
// export function menuJump(item) {
// const { is_tab, link, link_type } = item;
// switch (link_type) {
// case 0:
// // 本地跳转
// if (is_tab) {
// uni.switchTab({
// url: link,
// });
// return;
// }
// uni.navigateTo({
// url: link,
// });
// break;
// case 7:
// // webview
// uni.navigateTo({
// url: "/pages/webview/webview?url=" + link,
// });
// break;
// case 3: // tabbar
// }
// }
//菜单跳转
export function menuJump(item) {
const { is_tab, link, link_type, category_id, mnp_params } = item
if (is_tab) {
if(link_type==2){
uni.setStorageSync('category_id',category_id)
}
uni.switchTab({
url: link
})
return
} else {
switch (
// 0-基础页面:1-普通商品:2-平台分类;3-商家列表;4-活动专区;5-秒杀商品;6-拼团商品:7-自定义链接;8-微信小程序;
link_type //link_type -0基础页面 1-普通商品 2-租赁商品 3-商品分类 4-租赁分类 5-自定义链接 6-微信小程序
) {
case 0:
uni.navigateTo({
url: link
})
break
case 1:
uni.navigateTo({
url: link
})
break
case 2:
uni.navigateTo({
url: link + '?category_id=' + category_id
})
break
case 3:
uni.navigateTo({
url: link + '?id=' + category_id
})
break
case 4:
uni.navigateTo({
url: link + '?category_id=' + category_id
})
break
case 5:
uni.navigateTo({
url: link
})
break
case 6:
uni.navigateTo({
url: link
})
break
case 7:
// webview
uni.navigateTo({
url: '/pages/webview/webview?url=' + link
})
break
case 8:
wx.navigateToMiniProgram({
appId: mnp_params.mnp_app_id,
path: mnp_params.mnp_path
})
break
}
}
}
export function uploadFile(path, options) {
const { header, name } = options || {};
return new Promise((resolve, reject) => {
uni.uploadFile({
url: baseURL + "/api/file/formimage",
filePath: path,
name: name || "file",
header: {
token: store.getters.token,
...header,
// version: '1.2.1.20210717'
},
fileType: "image",
cloudPath: "",
success: (res) => {
try {
console.log(path);
console.log("uploadFile res ==> ", res);
let data = JSON.parse(res.data);
if (data.code == 1) {
resolve(data.data);
} else {
reject();
}
} catch (e) {
console.log(e);
reject();
}
},
fail: (err) => {
console.log(err);
reject();
},
});
});
}
//当前页面
export function currentPage() {
let pages = getCurrentPages();
let currentPage = pages[pages.length - 1];
return currentPage || {};
}
// H5复制方法
export function copy(str) {
// #ifdef H5
let aux = document.createElement("input");
aux.setAttribute("value", str);
document.body.appendChild(aux);
aux.select();
document.execCommand("copy");
document.body.removeChild(aux);
uni.showToast({
title: "复制成功",
});
// #endif
// #ifndef H5
uni.setClipboardData({
data: str.toString(),
});
// #endif
}
// #ifdef MP-WEIXIN
export function toLivePlayer(roomId) {
wx.navigateTo({
url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}`,
});
}
// #endif
/**
* @description 判断系统端
*/
export function getClient() {
return new Promise((resolve, reject) => {
uni.getSystemInfo({
success({ platform }) {
resolve(platform);
},
fail(err) {
reject(err);
console.log(err);
},
});
});
}
/**
* @description 获取当前微信小程序基础库版本号
*/
export function getBaseLibraryVersion() {
const { SDKVersion } = wx.getSystemInfoSync();
return SDKVersion;
}
/**
* @description 用于比较当前微信基础库版本与目标基础库版本
* 示例用法:比较小程序基础库版本是否大于等于 2.12.0 compareWeChatVersion("2.12.0")
* return 1 =>当前版本大于目标版本 return -1 =>当前版本小于目标版本 return 0 =>当前版本等于目标版本
* @param {string} targetVersion 目标微信版本号
*
*/
export function compareWeChatVersion(targetVersion) {
const currentVersion = getBaseLibraryVersion();
if (currentVersion === targetVersion) {
return 0; // 当前版本与目标版本相同
} else if (currentVersion > targetVersion) {
return 1; // 当前版本大于目标版本
} else {
return -1; // 当前版本小于目标版本
}
}

117
utils/type.js Normal file
View File

@ -0,0 +1,117 @@
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
//分页状态
export const loadingType = {
LOADING: "loading",
FINISHED: "finished",
ERROR: "error",
EMPTY: "empty",
};
//支付方式
export const payWay = {
WECHAT: 1,
BALANCE: 3,
};
export const orderType = {
ALL: "all",
//全部
PAY: "pay",
//待付款
DELIVERY: "delivery",
//待收货
FINISH: "finish",
//待收货
CLOSE: "close", //待收货
};
// 售后状态
export const afterSaleType = {
// 售后申请
NORMAL: "normal",
// 处理中
HANDLING: "apply",
// 已处理
FINISH: "finish",
};
// 售后退款操作
export const refundOptType = {
// 仅退款
ONLY_REFUND: 0,
// 退货退款
REFUNDS: 1,
};
// 短信发送
export const SMSType = {
// 注册
REGISTER: "ZCYZ",
// 找回密码
FINDPWD: "ZHMM",
// 登陆
LOGIN: "YZMDL",
// 更换手机号
CHANGE_MOBILE: "BGSJHM",
// 绑定手机号
BIND: "BDSJHM",
// 商家入驻申请验证
SJSQYZ: "SJSQYZ",
};
// 分销订单状态
export const distributionOrder = {
ALL: 0,
WAIT_RETURN: 1,
HANDLED: 2,
INVALED: 3,
};
// 排序类型
export const sortType = {
NONE: "",
ASC: "asc",
DESC: "desc",
};
export const groupType = {
ALL: -1,
PROGESS: 0,
SUCCESS: 1,
FAIL: 2,
};
export const bargainType = {
ALL: -1,
BARGINNING: 0,
SUCCESS: 1,
FAIL: 2,
};
// 发票类型
export const invoiceType = {
SETTLEMENT: 0,
ORDERDETAILEdit: 1,
ORDERDETAILADD: 2,
};
//系统端
export const Client = {
ANDROID: "android",
IOS: "ios",
};

197
utils/wechath5.js Normal file
View File

@ -0,0 +1,197 @@
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
// #ifdef H5
import weixin from '@/js_sdk/jweixin-module'
import { isAndroid } from './tools'
import { getJsconfig, getCodeUrl, wechatLogin } from '@/api/app'
import store from '../store'
import Cache from './cache'
class Wechath5 {
//获取微信配置url
signLink() {
if (typeof window.entryUrl === 'undefined' || window.entryUrl === '') {
window.entryUrl = location.href.split('#')[0]
}
console.log(location.href.split('#')[0])
return isAndroid() ? location.href.split('#')[0] : window.entryUrl
}
//微信sdk配置
config() {
return new Promise((resolve) => {
getJsconfig().then((res) => {
if (res.code == 1) {
let config = res.data.config
weixin.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来若要查看传入的参数可以在pc端打开参数信息会通过log打出仅在pc端时才会打印。
appId: config.appId, // 必填,公众号的唯一标识
timestamp: config.timestamp, // 必填,生成签名的时间戳
nonceStr: config.nonceStr, // 必填,生成签名的随机串
signature: config.signature, // 必填,签名
jsApiList: config.jsApiList // 必填需要使用的JS接口列表
})
resolve()
}
})
})
}
//获取微信登录url
getWxUrl() {
getCodeUrl().then((res) => {
if (res.code == 1) {
location.href = res.data.url
}
})
}
//微信授权
authLogin(code) {
return new Promise((resolve, reject) => {
wechatLogin({
code
}).then((res) => {
if (res.code == 1) {
store.commit('login', {
token: res.data.token
})
resolve(res.data)
}
})
})
}
//微信分享
share(option) {
weixin.ready(() => {
const { shareTitle, shareLink, shareImage, shareDesc } = option
weixin.updateTimelineShareData({
title: shareTitle, // 分享标题
link: shareLink, // 分享链接该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: shareImage, // 分享图标
success: function (res) {
// 设置成功
}
})
// 发送给好友
weixin.updateAppMessageShareData({
title: shareTitle, // 分享标题
link: shareLink, // 分享链接该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: shareImage, // 分享图标
desc: shareDesc,
success: function (res) {
// 设置成功
}
})
// 发送到tx微博
weixin.onMenuShareWeibo({
title: shareTitle, // 分享标题
link: shareLink, // 分享链接该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: shareImage, // 分享图标
desc: shareDesc,
success: function (res) {
// 设置成功
}
})
})
}
wxPay(opt) {
return new Promise((reslove, reject) => {
weixin.ready(() => {
weixin.chooseWXPay({
timestamp: opt.timeStamp, // 支付签名时间戳注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
nonceStr: opt.nonceStr, // 支付签名随机串,不长于 32 位
package: opt.package, // 统一支付接口返回的prepay_id参数值提交格式如prepay_id=***
signType: opt.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
paySign: opt.paySign, // 支付签名
success: (res) => {
console.log(res)
reslove()
},
cancel: (res) => {
reject()
},
fail: (res) => {
reject()
}
})
})
})
}
getWxAddress() {
return new Promise((reslove, reject) => {
weixin.ready(() => {
weixin.openAddress({
success: (res) => {
reslove(res)
}
})
})
})
}
getLocation() {
return new Promise((reslove, reject) => {
weixin.ready(() => {
weixin.getLocation({
type: 'gcj02',
success: (res) => {
reslove(res)
},
fail: (res) => {
reject(res)
}
})
})
})
}
reviceTransfer(mchId, appId, packageInfo) {
return new Promise((reslove, reject) => {
weixin.ready(() => {
weixin.checkJsApi({
jsApiList: ['requestMerchantTransfer'],
success: function (res) {
if (res.checkResult['requestMerchantTransfer']) {
WeixinJSBridge.invoke(
'requestMerchantTransfer',
{
mchId,
appId,
package: packageInfo
},
function (res) {
if (res.err_msg === 'requestMerchantTransfer:ok') {
reslove(res.err_msg)
} else {
reject(res.err_msg)
}
}
)
} else {
alert('你的微信版本过低,请更新至最新版本。')
}
}
})
})
})
}
}
export default new Wechath5()
// #endif