feat(登录)

This commit is contained in:
unknown 2024-05-29 01:29:31 +08:00
parent a7acb9dce0
commit c611e44858
7 changed files with 246 additions and 260 deletions

View File

@ -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": ""
}
}
]
}

View File

@ -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>

View File

@ -1,48 +1,48 @@
import request from '@/peach/request'
import request from "@/peach/request";
const AuthUtil = {
login: (data) => {
return request({
url: '/particulars/member/auth/sms-login',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '登陆中',
successMsg: '登陆成功',
},
})
},
// 发送手机验证码
sendSmsCode: (mobile, scene) => {
return request({
url: '/member/auth/send-sms-code',
method: 'POST',
data: {
mobile,
scene,
},
custom: {
loadingMsg: '发送中',
showSuccess: true,
successMsg: '发送成功',
},
})
},
// 刷新令牌
refreshToken: (refreshToken) => {
return request({
url: '/member/auth/refresh-token',
method: 'POST',
params: {
refreshToken,
},
custom: {
loading: false, // 不用加载中
showError: false, // 不展示错误提示
},
})
},
}
smsLogin: (data) => {
return request({
url: "/particulars/member/auth/sms-login",
method: "POST",
data,
custom: {
showSuccess: true,
loadingMsg: "登陆中",
successMsg: "登陆成功",
},
});
},
// 发送手机验证码
sendSmsCode: (mobile, scene) => {
return request({
url: "/member/auth/send-sms-code",
method: "POST",
data: {
mobile,
scene,
},
custom: {
loadingMsg: "发送中",
showSuccess: true,
successMsg: "发送成功",
},
});
},
// 刷新令牌
refreshToken: (refreshToken) => {
return request({
url: "/member/auth/refresh-token",
method: "POST",
params: {
refreshToken,
},
custom: {
loading: false, // 不用加载中
showError: false, // 不展示错误提示
},
});
},
};
export default AuthUtil
export default AuthUtil;

View File

@ -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,
}
baseUrl,
apiPath,
staticUrl,
};

View File

@ -45,7 +45,7 @@ function closeLoading() {
// 请求实例
const http = new Request({
baseUrl: baseUrl + apiPath,
baseURL: baseUrl + apiPath,
timeout: 8000,
method: "GET",
header: {

View File

@ -1,185 +1,198 @@
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,
params = {},
options = {
redirect: false,
}
path,
params = {},
options = {
redirect: false,
}
) => {
let page = '' // 跳转页面
let query = '' // 页面参数
let url = '' // 跳转页面完整路径
let page = ""; // 跳转页面
let query = ""; // 页面参数
let url = ""; // 跳转页面完整路径
if (isString(path)) {
// 判断跳转类型是 path 还是http
if (startsWith(path, 'http')) {
// #ifdef H5
window.location = path
return
// #endif
// #ifndef H5
page = `/pages/public/webview`
query = `url=${encodeURIComponent(path)}`
// #endif
} else if (startsWith(path, 'action:')) {
handleAction(path)
return
} else {
;[page, query] = path.split('?')
}
if (!isEmpty(params)) {
let query2 = paramsToQuery(params)
if (isEmpty(query)) {
query = query2
} else {
query += '&' + query2
}
}
if (isString(path)) {
// 判断跳转类型是 path 还是http
if (startsWith(path, "http")) {
// #ifdef H5
window.location = path;
return;
// #endif
// #ifndef H5
page = `/pages/public/webview`;
query = `url=${encodeURIComponent(path)}`;
// #endif
} else if (startsWith(path, "action:")) {
handleAction(path);
return;
} else {
[page, query] = path.split("?");
}
if (isObject(path)) {
page = path.url
if (!isNil(path.params)) {
query = paramsToQuery(path.params)
}
if (!isEmpty(params)) {
let query2 = paramsToQuery(params);
if (isEmpty(query)) {
query = query2;
} else {
query += "&" + query2;
}
}
}
const nextRoute = ROUTES_MAP[page]
// 未找到指定跳转页面
// mark: 跳转404页
if (!nextRoute) {
console.log(`%c跳转路径参数错误<${page || 'EMPTY'}>`, 'color:red;background:yellow')
return
if (isObject(path)) {
page = path.url;
if (!isNil(path.params)) {
query = paramsToQuery(path.params);
}
}
// 页面登录拦截
if (nextRoute.meta?.auth && !$store('user').isLogin) {
showAuthModal()
return
}
const nextRoute = ROUTES_MAP[page];
url = page
if (!isEmpty(query)) {
url += `?${query}`
}
// 未找到指定跳转页面
// mark: 跳转404页
if (!nextRoute) {
console.log(
`%c跳转路径参数错误<${page || "EMPTY"}>`,
"color:red;background:yellow"
);
return;
}
// 跳转底部导航
if (TABBAR.includes(page)) {
uni.switchTab({
url,
})
return
}
// 页面登录拦截
if (nextRoute.meta?.auth && !$store("user").isLogin) {
uni.redirectTo({
url: "/pages/index/login",
});
return;
}
// 使用redirect跳转
if (options.redirect) {
uni.redirectTo({
url,
})
return
}
url = page;
if (!isEmpty(query)) {
url += `?${query}`;
}
uni.navigateTo({
url,
})
}
// 跳转底部导航
if (TABBAR.includes(page)) {
uni.switchTab({
url,
});
return;
}
// 使用redirect跳转
if (options.redirect) {
uni.redirectTo({
url,
});
return;
}
uni.navigateTo({
url,
});
};
// 限流 防止重复点击跳转
function go(...args) {
throttle(() => {
_go(...args)
})
throttle(() => {
_go(...args);
});
}
function paramsToQuery(params) {
if (isEmpty(params)) {
return ''
}
// return new URLSearchParams(Object.entries(params)).toString();
let query = []
for (let key in params) {
query.push(key + '=' + params[key])
}
if (isEmpty(params)) {
return "";
}
// return new URLSearchParams(Object.entries(params)).toString();
let query = [];
for (let key in params) {
query.push(key + "=" + params[key]);
}
return query.join('&')
return query.join("&");
}
function back() {
// #ifdef H5
history.back()
// #endif
// #ifdef H5
history.back();
// #endif
// #ifndef H5
uni.navigateBack()
// #endif
// #ifndef H5
uni.navigateBack();
// #endif
}
function redirect(path, params = {}) {
go(path, params, {
redirect: true,
})
go(path, params, {
redirect: true,
});
}
// 检测是否有浏览器历史
function hasHistory() {
// #ifndef H5
const pages = getCurrentPages()
if (pages.length > 1) {
return true
}
return false
// #endif
// #ifndef H5
const pages = getCurrentPages();
if (pages.length > 1) {
return true;
}
return false;
// #endif
// #ifdef H5
return !!history.back
// #endif
// #ifdef H5
return !!history.back;
// #endif
}
function getCurrentRoute(field = '') {
let currentPage = getCurrentPage()
// #ifdef MP
currentPage.$page['route'] = currentPage.route
currentPage.$page['options'] = currentPage.options
// #endif
if (field !== '') {
return currentPage.$page[field]
} else {
return currentPage.$page
}
function getCurrentRoute(field = "") {
let currentPage = getCurrentPage();
// #ifdef MP
currentPage.$page["route"] = currentPage.route;
currentPage.$page["options"] = currentPage.options;
// #endif
if (field !== "") {
return currentPage.$page[field];
} else {
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(':')
switch (action[1]) {
case 'showShareModal':
showShareModal()
break
}
const action = path.split(":");
switch (action[1]) {
case "showShareModal":
showShareModal();
break;
}
}
function error(errCode, errMsg = '') {
redirect('/pages/public/error', {
errCode,
errMsg,
})
function error(errCode, errMsg = "") {
redirect("/pages/public/error", {
errCode,
errMsg,
});
}
export default {
go,
back,
hasHistory,
redirect,
getCurrentPage,
getCurrentRoute,
error,
}
go,
back,
hasHistory,
redirect,
getCurrentPage,
getCurrentRoute,
error,
};

View File

@ -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()
if (lastUpdateTime.value + 5000 > nowTime) {
return
async function updateUserData() {
const nowTime = new Date().getTime();
if (lastUpdateTime.value + 5000 > nowTime) {
return;
}
lastUpdateTime.value = nowTime
await getUserInfo()
getWallet()
getNumData()
return userInfo.value
lastUpdateTime.value = nowTime;
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,
};
},
{