feat(登录)
This commit is contained in:
parent
a7acb9dce0
commit
c611e44858
47
pages.json
47
pages.json
|
@ -14,7 +14,7 @@
|
|||
"navigationBarTitleText": "订单"
|
||||
},
|
||||
"meta": {
|
||||
"auth": false
|
||||
"auth": true
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -29,10 +29,10 @@
|
|||
{
|
||||
"path": "pages/index/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "uni-app"
|
||||
"navigationBarTitleText": "首页"
|
||||
},
|
||||
"meta": {
|
||||
"auth": false
|
||||
"auth": true
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -66,50 +66,13 @@
|
|||
"subPackages": [
|
||||
{
|
||||
"root": "pages/public",
|
||||
"pages": [{
|
||||
"path": "setting",
|
||||
"style": {
|
||||
"navigationBarTitleText": "系统设置"
|
||||
},
|
||||
"meta": {
|
||||
"sync": true,
|
||||
"title": "系统设置",
|
||||
"group": "通用"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "richtext",
|
||||
"style": {
|
||||
"navigationBarTitleText": "富文本"
|
||||
},
|
||||
"meta": {
|
||||
"sync": true,
|
||||
"title": "富文本",
|
||||
"group": "通用"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "faq",
|
||||
"style": {
|
||||
"navigationBarTitleText": "常见问题"
|
||||
},
|
||||
"meta": {
|
||||
"sync": true,
|
||||
"title": "常见问题",
|
||||
"group": "通用"
|
||||
}
|
||||
},
|
||||
"pages": [
|
||||
|
||||
{
|
||||
"path": "error",
|
||||
"style": {
|
||||
"navigationBarTitleText": "错误页面"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "webview",
|
||||
"style": {
|
||||
"navigationBarTitleText": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { code, mobile } from '@/peach/validate/form';
|
||||
import AuthUtil from '@/peach/api/member/auth';
|
||||
import peach from '@/peach'
|
||||
import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/peach/hooks/useModal';
|
||||
|
||||
|
@ -50,8 +51,8 @@ const state = ref({
|
|||
agreeStatus: false,
|
||||
isShaking: false,
|
||||
model: {
|
||||
mobile: '',
|
||||
code: '',
|
||||
mobile: '15036370128',
|
||||
code: '9999',
|
||||
},
|
||||
rules: {
|
||||
mobile,
|
||||
|
@ -73,7 +74,7 @@ async function smsLoginSubmit() {
|
|||
console.log('err', err)
|
||||
})
|
||||
if (!validate) return
|
||||
if (!state.agreeStatus) {
|
||||
if (!state.value.agreeStatus) {
|
||||
state.value.isShaking = true
|
||||
setTimeout(() => {
|
||||
state.value.isShaking = false
|
||||
|
@ -99,6 +100,14 @@ async function smsLoginSubmit() {
|
|||
border-radius: 41rpx;
|
||||
padding: 0 10rpx;
|
||||
}
|
||||
|
||||
.is-focused {
|
||||
::v-deep .content-clear-icon {
|
||||
.uniui-clear {
|
||||
color: red !important
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1,39 +1,39 @@
|
|||
import request from '@/peach/request'
|
||||
import request from "@/peach/request";
|
||||
|
||||
const AuthUtil = {
|
||||
login: (data) => {
|
||||
smsLogin: (data) => {
|
||||
return request({
|
||||
url: '/particulars/member/auth/sms-login',
|
||||
method: 'POST',
|
||||
url: "/particulars/member/auth/sms-login",
|
||||
method: "POST",
|
||||
data,
|
||||
custom: {
|
||||
showSuccess: true,
|
||||
loadingMsg: '登陆中',
|
||||
successMsg: '登陆成功',
|
||||
loadingMsg: "登陆中",
|
||||
successMsg: "登陆成功",
|
||||
},
|
||||
})
|
||||
});
|
||||
},
|
||||
// 发送手机验证码
|
||||
sendSmsCode: (mobile, scene) => {
|
||||
return request({
|
||||
url: '/member/auth/send-sms-code',
|
||||
method: 'POST',
|
||||
url: "/member/auth/send-sms-code",
|
||||
method: "POST",
|
||||
data: {
|
||||
mobile,
|
||||
scene,
|
||||
},
|
||||
custom: {
|
||||
loadingMsg: '发送中',
|
||||
loadingMsg: "发送中",
|
||||
showSuccess: true,
|
||||
successMsg: '发送成功',
|
||||
successMsg: "发送成功",
|
||||
},
|
||||
})
|
||||
});
|
||||
},
|
||||
// 刷新令牌
|
||||
refreshToken: (refreshToken) => {
|
||||
return request({
|
||||
url: '/member/auth/refresh-token',
|
||||
method: 'POST',
|
||||
url: "/member/auth/refresh-token",
|
||||
method: "POST",
|
||||
params: {
|
||||
refreshToken,
|
||||
},
|
||||
|
@ -41,8 +41,8 @@ const AuthUtil = {
|
|||
loading: false, // 不用加载中
|
||||
showError: false, // 不展示错误提示
|
||||
},
|
||||
})
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export default AuthUtil
|
||||
export default AuthUtil;
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
// 开发环境配置
|
||||
export let baseUrl
|
||||
export let version
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
baseUrl = import.meta.env.MALL_DEV_BASE_URL
|
||||
export let baseUrl;
|
||||
export let version;
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
baseUrl = import.meta.env.MALL_DEV_BASE_URL;
|
||||
} else {
|
||||
baseUrl = import.meta.env.MALL_BASE_URL
|
||||
baseUrl = import.meta.env.MALL_BASE_URL;
|
||||
}
|
||||
version = import.meta.env.MALL_VERSION
|
||||
console.log(`[🍑商城 ${version}] http://ankkaya.top`)
|
||||
version = import.meta.env.MALL_VERSION;
|
||||
console.log(`[🍑商城 ${version}] http://ankkaya.top`);
|
||||
console.log(baseUrl);
|
||||
|
||||
export const apiPath = import.meta.env.MALL_API_PATH
|
||||
export const staticUrl = import.meta.env.MALL_STATIC_URL
|
||||
export const apiPath = import.meta.env.MALL_API_PATH;
|
||||
export const staticUrl = import.meta.env.MALL_STATIC_URL;
|
||||
|
||||
export default {
|
||||
baseUrl,
|
||||
apiPath,
|
||||
staticUrl,
|
||||
}
|
||||
};
|
||||
|
|
|
@ -45,7 +45,7 @@ function closeLoading() {
|
|||
|
||||
// 请求实例
|
||||
const http = new Request({
|
||||
baseUrl: baseUrl + apiPath,
|
||||
baseURL: baseUrl + apiPath,
|
||||
timeout: 8000,
|
||||
method: "GET",
|
||||
header: {
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
import $store from '@/peach/store'
|
||||
import { showAuthModal, showShareModal } from '@/peach/hooks/useModal'
|
||||
import { isNumber, isString, isEmpty, startsWith, isObject, isNil, clone } from 'lodash'
|
||||
import throttle from '@/peach/helper/throttle'
|
||||
import $store from "@/peach/store";
|
||||
import { showShareModal } from "@/peach/hooks/useModal";
|
||||
import {
|
||||
isNumber,
|
||||
isString,
|
||||
isEmpty,
|
||||
startsWith,
|
||||
isObject,
|
||||
isNil,
|
||||
clone,
|
||||
} from "lodash";
|
||||
import throttle from "@/peach/helper/throttle";
|
||||
|
||||
const _go = (
|
||||
path,
|
||||
|
@ -10,168 +18,173 @@ const _go = (
|
|||
redirect: false,
|
||||
}
|
||||
) => {
|
||||
let page = '' // 跳转页面
|
||||
let query = '' // 页面参数
|
||||
let url = '' // 跳转页面完整路径
|
||||
let page = ""; // 跳转页面
|
||||
let query = ""; // 页面参数
|
||||
let url = ""; // 跳转页面完整路径
|
||||
|
||||
if (isString(path)) {
|
||||
// 判断跳转类型是 path | 还是http
|
||||
if (startsWith(path, 'http')) {
|
||||
if (startsWith(path, "http")) {
|
||||
// #ifdef H5
|
||||
window.location = path
|
||||
return
|
||||
window.location = path;
|
||||
return;
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
page = `/pages/public/webview`
|
||||
query = `url=${encodeURIComponent(path)}`
|
||||
page = `/pages/public/webview`;
|
||||
query = `url=${encodeURIComponent(path)}`;
|
||||
// #endif
|
||||
} else if (startsWith(path, 'action:')) {
|
||||
handleAction(path)
|
||||
return
|
||||
} else if (startsWith(path, "action:")) {
|
||||
handleAction(path);
|
||||
return;
|
||||
} else {
|
||||
;[page, query] = path.split('?')
|
||||
[page, query] = path.split("?");
|
||||
}
|
||||
if (!isEmpty(params)) {
|
||||
let query2 = paramsToQuery(params)
|
||||
let query2 = paramsToQuery(params);
|
||||
if (isEmpty(query)) {
|
||||
query = query2
|
||||
query = query2;
|
||||
} else {
|
||||
query += '&' + query2
|
||||
query += "&" + query2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isObject(path)) {
|
||||
page = path.url
|
||||
page = path.url;
|
||||
if (!isNil(path.params)) {
|
||||
query = paramsToQuery(path.params)
|
||||
query = paramsToQuery(path.params);
|
||||
}
|
||||
}
|
||||
|
||||
const nextRoute = ROUTES_MAP[page]
|
||||
const nextRoute = ROUTES_MAP[page];
|
||||
|
||||
// 未找到指定跳转页面
|
||||
// mark: 跳转404页
|
||||
if (!nextRoute) {
|
||||
console.log(`%c跳转路径参数错误<${page || 'EMPTY'}>`, 'color:red;background:yellow')
|
||||
return
|
||||
console.log(
|
||||
`%c跳转路径参数错误<${page || "EMPTY"}>`,
|
||||
"color:red;background:yellow"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 页面登录拦截
|
||||
if (nextRoute.meta?.auth && !$store('user').isLogin) {
|
||||
showAuthModal()
|
||||
return
|
||||
if (nextRoute.meta?.auth && !$store("user").isLogin) {
|
||||
uni.redirectTo({
|
||||
url: "/pages/index/login",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
url = page
|
||||
url = page;
|
||||
if (!isEmpty(query)) {
|
||||
url += `?${query}`
|
||||
url += `?${query}`;
|
||||
}
|
||||
|
||||
// 跳转底部导航
|
||||
if (TABBAR.includes(page)) {
|
||||
uni.switchTab({
|
||||
url,
|
||||
})
|
||||
return
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用redirect跳转
|
||||
if (options.redirect) {
|
||||
uni.redirectTo({
|
||||
url,
|
||||
})
|
||||
return
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
uni.navigateTo({
|
||||
url,
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 限流 防止重复点击跳转
|
||||
function go(...args) {
|
||||
throttle(() => {
|
||||
_go(...args)
|
||||
})
|
||||
_go(...args);
|
||||
});
|
||||
}
|
||||
|
||||
function paramsToQuery(params) {
|
||||
if (isEmpty(params)) {
|
||||
return ''
|
||||
return "";
|
||||
}
|
||||
// return new URLSearchParams(Object.entries(params)).toString();
|
||||
let query = []
|
||||
let query = [];
|
||||
for (let key in params) {
|
||||
query.push(key + '=' + params[key])
|
||||
query.push(key + "=" + params[key]);
|
||||
}
|
||||
|
||||
return query.join('&')
|
||||
return query.join("&");
|
||||
}
|
||||
|
||||
function back() {
|
||||
// #ifdef H5
|
||||
history.back()
|
||||
history.back();
|
||||
// #endif
|
||||
|
||||
// #ifndef H5
|
||||
uni.navigateBack()
|
||||
uni.navigateBack();
|
||||
// #endif
|
||||
}
|
||||
|
||||
function redirect(path, params = {}) {
|
||||
go(path, params, {
|
||||
redirect: true,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// 检测是否有浏览器历史
|
||||
function hasHistory() {
|
||||
// #ifndef H5
|
||||
const pages = getCurrentPages()
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 1) {
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
return false
|
||||
return false;
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
return !!history.back
|
||||
return !!history.back;
|
||||
// #endif
|
||||
}
|
||||
|
||||
function getCurrentRoute(field = '') {
|
||||
let currentPage = getCurrentPage()
|
||||
function getCurrentRoute(field = "") {
|
||||
let currentPage = getCurrentPage();
|
||||
// #ifdef MP
|
||||
currentPage.$page['route'] = currentPage.route
|
||||
currentPage.$page['options'] = currentPage.options
|
||||
currentPage.$page["route"] = currentPage.route;
|
||||
currentPage.$page["options"] = currentPage.options;
|
||||
// #endif
|
||||
if (field !== '') {
|
||||
return currentPage.$page[field]
|
||||
if (field !== "") {
|
||||
return currentPage.$page[field];
|
||||
} else {
|
||||
return currentPage.$page
|
||||
return currentPage.$page;
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentPage() {
|
||||
let pages = getCurrentPages()
|
||||
return pages[pages.length - 1]
|
||||
let pages = getCurrentPages();
|
||||
return pages[pages.length - 1];
|
||||
}
|
||||
|
||||
function handleAction(path) {
|
||||
const action = path.split(':')
|
||||
const action = path.split(":");
|
||||
switch (action[1]) {
|
||||
case 'showShareModal':
|
||||
showShareModal()
|
||||
break
|
||||
case "showShareModal":
|
||||
showShareModal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function error(errCode, errMsg = '') {
|
||||
redirect('/pages/public/error', {
|
||||
function error(errCode, errMsg = "") {
|
||||
redirect("/pages/public/error", {
|
||||
errCode,
|
||||
errMsg,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
|
@ -182,4 +195,4 @@ export default {
|
|||
getCurrentPage,
|
||||
getCurrentRoute,
|
||||
error,
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { ref } from "vue";
|
||||
import { defineStore } from "pinia";
|
||||
import $share from '@/peach/platform/share'
|
||||
import $share from "@/peach/platform/share";
|
||||
import { isEmpty, cloneDeep, clone } from "lodash";
|
||||
|
||||
// 默认用户信息
|
||||
|
@ -37,7 +37,7 @@ const useUserStore = defineStore(
|
|||
const userWallet = ref(clone(defaultWallet));
|
||||
const userNumData = ref(cloneDeep(defaultNumData));
|
||||
const isLogin = ref(!!uni.getStorageSync("token"));
|
||||
const lastUpdateTime = ref(0)
|
||||
const lastUpdateTime = ref(0);
|
||||
|
||||
function getUserInfo() {}
|
||||
|
||||
|
@ -67,34 +67,34 @@ const useUserStore = defineStore(
|
|||
userNumData.value = cloneDeep(defaultNumData);
|
||||
}
|
||||
|
||||
function updateUserData() {
|
||||
const nowTime = new Date().getTime()
|
||||
async function updateUserData() {
|
||||
const nowTime = new Date().getTime();
|
||||
if (lastUpdateTime.value + 5000 > nowTime) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
lastUpdateTime.value = nowTime
|
||||
lastUpdateTime.value = nowTime;
|
||||
|
||||
await getUserInfo()
|
||||
getWallet()
|
||||
getNumData()
|
||||
return userInfo.value
|
||||
await getUserInfo();
|
||||
getWallet();
|
||||
getNumData();
|
||||
return userInfo.value;
|
||||
}
|
||||
|
||||
function loginAfter() {
|
||||
updateUserData()
|
||||
$share.getShareInfo()
|
||||
updateUserData();
|
||||
$share.getShareInfo();
|
||||
}
|
||||
|
||||
function logOut() {
|
||||
resetUserData();
|
||||
return !isLogin.value
|
||||
return !isLogin.value;
|
||||
}
|
||||
|
||||
return {
|
||||
userInfo,
|
||||
isLogin,
|
||||
setToken,
|
||||
logOut
|
||||
logOut,
|
||||
};
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue