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": "订单" "navigationBarTitleText": "订单"
}, },
"meta": { "meta": {
"auth": false "auth": true
} }
}, },
{ {
@ -29,10 +29,10 @@
{ {
"path": "pages/index/index", "path": "pages/index/index",
"style": { "style": {
"navigationBarTitleText": "uni-app" "navigationBarTitleText": "首页"
}, },
"meta": { "meta": {
"auth": false "auth": true
} }
}, },
{ {
@ -66,50 +66,13 @@
"subPackages": [ "subPackages": [
{ {
"root": "pages/public", "root": "pages/public",
"pages": [{ "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": "通用"
}
},
{ {
"path": "error", "path": "error",
"style": { "style": {
"navigationBarTitleText": "错误页面" "navigationBarTitleText": "错误页面"
} }
},
{
"path": "webview",
"style": {
"navigationBarTitleText": ""
}
} }
] ]
} }

View File

@ -39,6 +39,7 @@
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
import { code, mobile } from '@/peach/validate/form'; import { code, mobile } from '@/peach/validate/form';
import AuthUtil from '@/peach/api/member/auth';
import peach from '@/peach' import peach from '@/peach'
import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/peach/hooks/useModal'; import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/peach/hooks/useModal';
@ -50,8 +51,8 @@ const state = ref({
agreeStatus: false, agreeStatus: false,
isShaking: false, isShaking: false,
model: { model: {
mobile: '', mobile: '15036370128',
code: '', code: '9999',
}, },
rules: { rules: {
mobile, mobile,
@ -73,7 +74,7 @@ async function smsLoginSubmit() {
console.log('err', err) console.log('err', err)
}) })
if (!validate) return if (!validate) return
if (!state.agreeStatus) { if (!state.value.agreeStatus) {
state.value.isShaking = true state.value.isShaking = true
setTimeout(() => { setTimeout(() => {
state.value.isShaking = false state.value.isShaking = false
@ -99,6 +100,14 @@ async function smsLoginSubmit() {
border-radius: 41rpx; border-radius: 41rpx;
padding: 0 10rpx; padding: 0 10rpx;
} }
.is-focused {
::v-deep .content-clear-icon {
.uniui-clear {
color: red !important
}
}
}
} }
} }
</style> </style>

View File

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

View File

@ -1,19 +1,20 @@
// 开发环境配置 // 开发环境配置
export let baseUrl export let baseUrl;
export let version export let version;
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === "development") {
baseUrl = import.meta.env.MALL_DEV_BASE_URL baseUrl = import.meta.env.MALL_DEV_BASE_URL;
} else { } else {
baseUrl = import.meta.env.MALL_BASE_URL baseUrl = import.meta.env.MALL_BASE_URL;
} }
version = import.meta.env.MALL_VERSION version = import.meta.env.MALL_VERSION;
console.log(`[🍑商城 ${version}] http://ankkaya.top`) console.log(`[🍑商城 ${version}] http://ankkaya.top`);
console.log(baseUrl);
export const apiPath = import.meta.env.MALL_API_PATH export const apiPath = import.meta.env.MALL_API_PATH;
export const staticUrl = import.meta.env.MALL_STATIC_URL export const staticUrl = import.meta.env.MALL_STATIC_URL;
export default { export default {
baseUrl, baseUrl,
apiPath, apiPath,
staticUrl, staticUrl,
} };

View File

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

View File

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

View File

@ -1,6 +1,6 @@
import { ref } from "vue"; import { ref } from "vue";
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import $share from '@/peach/platform/share' import $share from "@/peach/platform/share";
import { isEmpty, cloneDeep, clone } from "lodash"; import { isEmpty, cloneDeep, clone } from "lodash";
// 默认用户信息 // 默认用户信息
@ -37,7 +37,7 @@ const useUserStore = defineStore(
const userWallet = ref(clone(defaultWallet)); const userWallet = ref(clone(defaultWallet));
const userNumData = ref(cloneDeep(defaultNumData)); const userNumData = ref(cloneDeep(defaultNumData));
const isLogin = ref(!!uni.getStorageSync("token")); const isLogin = ref(!!uni.getStorageSync("token"));
const lastUpdateTime = ref(0) const lastUpdateTime = ref(0);
function getUserInfo() {} function getUserInfo() {}
@ -67,34 +67,34 @@ const useUserStore = defineStore(
userNumData.value = cloneDeep(defaultNumData); userNumData.value = cloneDeep(defaultNumData);
} }
function updateUserData() { async function updateUserData() {
const nowTime = new Date().getTime() const nowTime = new Date().getTime();
if (lastUpdateTime.value + 5000 > nowTime) { if (lastUpdateTime.value + 5000 > nowTime) {
return return;
} }
lastUpdateTime.value = nowTime lastUpdateTime.value = nowTime;
await getUserInfo() await getUserInfo();
getWallet() getWallet();
getNumData() getNumData();
return userInfo.value return userInfo.value;
} }
function loginAfter() { function loginAfter() {
updateUserData() updateUserData();
$share.getShareInfo() $share.getShareInfo();
} }
function logOut() { function logOut() {
resetUserData(); resetUserData();
return !isLogin.value return !isLogin.value;
} }
return { return {
userInfo, userInfo,
isLogin, isLogin,
setToken, setToken,
logOut logOut,
}; };
}, },
{ {