初始化仓库

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

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
}