From c76922f37ddeeb3344304af453dd2f8befdedb89 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Tue, 30 Sep 2025 14:18:00 +0800
Subject: [PATCH] feat: app搭建调整
---
src/pages/map/index.vue | 7
src/api/map.js | 9
src/pages/login/index.vue | 277 ++++++++----------------
src/store/modules/user/index.js | 84 ------
src/plugins/permission.js | 4
src/utils/request/index.js | 31 +-
src/router/index.js | 10
README.md | 20 +
/dev/null | 15 -
src/api/user/index.js | 10
src/pages/user/index.vue | 57 ++--
src/utils/request/interceptors.js | 100 +-------
index.html | 2
package.json | 6
src/utils/index.js | 1
src/App.vue | 7
src/pages/work/index.vue | 2
17 files changed, 210 insertions(+), 432 deletions(-)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
deleted file mode 100644
index 4226a62..0000000
--- a/CONTRIBUTING.md
+++ /dev/null
@@ -1,67 +0,0 @@
-# 贡献指南
-
-感谢你对本项目的兴趣!我们欢迎任何形式的贡献,无论是报告 bug、提交功能请求、改进文档,还是直接提交代码。为了使贡献过程更加顺利,请按照以下指南进行操作。
-
-## 如何开始
-
-1. **Fork 项目**:首先将项目 `Fork` 到你的 `GitHub` 账户。
-2. **克隆到本地**:将你 `Fork` 后的仓库克隆到本地。
- ```bash
- git clone https://github.com/你的用户名/uniapp-vue3-template.git
- ```
-3. **创建分支**:在进行任何修改之前,先创建一个新的分支。
- ```bash
- git checkout -b feature/your-feature-name
- ```
-4. **进行修改**:根据你的需求进行代码修改或文档编辑。
-5. **提交更改**:完成修改后,使用以下命令提交更改:
- ```bash
- pnpm cz
- ```
-6. **推送分支**:将你的分支推送到 GitHub。
- ```bash
- git push origin feature/your-feature-name
- ```
-7. **创建 Pull Request**:在 `GitHub` 上,提交你的 `Pull Request`,描述清楚你所做的更改。
-
-## 提交代码规范
-
-- **代码格式**:只要你安装了依赖项,就不用担心代码风格。`Git` 钩子会在提交时为你格式化和修复它们。
-- **简洁明了的提交信息**:提交信息应简明扼要,说明改动的目的和内容。建议使用以下格式:
- ```
- [类型]:简要说明
- ```
- 例如:
- ```
- feat: 添加新功能
- fix: 修复 bug
- docs: 更新文档
- style: 格式调整
- refactor: 代码重构
- test: 添加/修改测试
- ```
-
-## 贡献前请注意
-
-- **讨论功能请求**:在提交功能请求之前,确保这个功能是项目当前的方向。
-- **修复 bug**:在修复 `bug` 之前,先检查现有的 `issue` 列表,看看是否有人已经报告了相同的问题。
-- **文档改进**:欢迎任何形式的文档改进。文档有时会被遗漏,但它对于项目的可用性至关重要。
-
-## 测试
-
-在提交 `Pull Request` 之前,请确保测试成功通过。如果有修改涉及到核心功能,请确保你的改动不会破坏现有的功能。
-
-## 行为规范
-
-希望在这个项目中创建一个友好和包容的社区。请遵循以下行为准则:
-
-- 尊重他人,避免人身攻击、歧视或骚扰。
-- 提供有建设性的反馈,不论是代码还是讨论。
-- 对不同的观点保持开放的态度,愿意倾听他人的建议。
-
-## 相关文档
-
-- [项目主页](https://github.com/oyjt/uniapp-vue3-template)
-- [问题追踪](https://github.com/oyjt/uniapp-vue3-template/issues)
-
-感谢你的贡献!期待与你的合作!
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 9eec64d..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2024 江阳小道
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/README.md b/README.md
index 96cc651..293637e 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,16 @@
+# 掌控智飞
+
+```
+npm install pnpm -g
+pnpm install
+pnpm run dev
+```
+
+
+
+
+
+
# uniapp 团队协作开发实践模板(Vue3)
[](https://github.com/oyjt/uniapp-vue3-template)
@@ -325,10 +338,3 @@
5. `shadcn-ui` 分支采用最新的 `tailwindcss v4.1` 版本,因为现阶段的 `unocss` 对于最新版 `tailwindcss` 支持还不够完善。
`shadcn-ui`并不太适合移动端使用,如果不喜欢可以移除,只保留纯净的框架。
-### 捐赠
-
-如果你觉得这个项目对你有帮助,你可以请作者喝饮料🍹
-
-<p align='center'>
-<img alt="微信收款码" src="./src/static/images/pay.png" height="330" style="display:inline-block; height:330px;">
-</p>
diff --git a/index.html b/index.html
index fb81ddc..0eb45d2 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html lang="en">
+<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<script>
diff --git a/package.json b/package.json
index 2b08074..d17745f 100644
--- a/package.json
+++ b/package.json
@@ -2,11 +2,9 @@
"name": "uniapp-vue3-project",
"type": "module",
"version": "1.5.0",
- "description": "uniapp 团队协作开发实践模板(Vue3)",
+ "description": "掌控智飞",
"author": {
- "name": "江阳小道",
- "email": "oyjt001@gmail.com",
- "github": "https://github.com/oyjt"
+ "name": "ztzf"
},
"license": "MIT",
"homepage": "https://github.com/oyjt/uniapp-vue3-template",
diff --git a/src/App.vue b/src/App.vue
index 466a749..c142132 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -4,17 +4,16 @@
* @LastEditors : yuan
* @LastEditTime : 2025-09-28 10:07:55
* @FilePath : \src\App.vue
- * @Description :
- * Copyright 2025 OBKoro1, All Rights Reserved.
+ * @Description :
+ * Copyright 2025 OBKoro1, All Rights Reserved.
* 2025-09-28 09:31:16
-->
<script setup>
import { onHide, onLaunch, onShow } from "@dcloudio/uni-app";
import { useAppStore } from "@/store";
-import { mpUpdate } from "@/utils/index";
+import {mpUpdate} from "@/utils/index";
const appStore = useAppStore();
-
onLaunch(() => {
console.log("App Launch");
diff --git a/src/api/index.js b/src/api/index.js
deleted file mode 100644
index 8026e4e..0000000
--- a/src/api/index.js
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * @Author : yuan
- * @Date : 2025-09-28 09:31:16
- * @LastEditors : yuan
- * @LastEditTime : 2025-09-28 09:44:00
- * @FilePath : \src\api\index.ts
- * @Description :
- * Copyright 2025 OBKoro1, All Rights Reserved.
- * 2025-09-28 09:31:16
- */
-import * as CommonApi from "./common"
-import * as UserApi from "./user"
-
-export { CommonApi, UserApi }
diff --git a/src/api/map.js b/src/api/map.js
new file mode 100644
index 0000000..9e905bb
--- /dev/null
+++ b/src/api/map.js
@@ -0,0 +1,9 @@
+import {request} from "@/utils/request"
+
+export const getDeviceRegionApi = data => {
+ return request({
+ url: '/drone-device-core/manage/api/v1/devices/getDeviceRegion',
+ method: 'post',
+ data: { hidden_flag: 0, ...data },
+ })
+}
diff --git a/src/api/user/index.js b/src/api/user/index.js
index 43c60a9..82da79f 100644
--- a/src/api/user/index.js
+++ b/src/api/user/index.js
@@ -6,11 +6,6 @@
import website from '@/config/website'
-/** 获取用户信息 */
-export const profile = params => get("/user/profile", {
- params
-})
-
/** 登录 */
export const login = data =>
post("/user/login", {
@@ -29,8 +24,8 @@
export const logout = () => post("/user/logout")
// 用户登录接口
-export const loginByUsername = (tenantId, deptId, roleId, username, password, type, key, code) =>
- request({
+export const loginByUsername = (tenantId, deptId, roleId, username, password, type, key, code) => {
+ return request({
url: '/blade-auth/oauth/token',
method: 'post',
header: {
@@ -49,3 +44,4 @@
type,
},
})
+}
diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue
index 9ef666e..caad501 100644
--- a/src/pages/login/index.vue
+++ b/src/pages/login/index.vue
@@ -2,209 +2,126 @@
<template>
<view>
<view class="login-form-wrap">
- <view class="title"> 欢迎登录 </view>
- <input v-model="tel" class="u-border-bottom" type="number" placeholder="请输入手机号" />
- <view class="u-border-bottom my-40rpx flex">
- <input v-model="code" class="flex-1" type="number" placeholder="请输入验证码" />
- <view>
- <u-code ref="uCodeRef" @change="codeChange" />
- <u-button :text="tips" type="success" size="mini" @click="getCode" />
- </view>
- </view>
+ <view class="title"> 掌控智飞</view>
+ <input v-model="loginForm.username" class="u-border-bottom" placeholder="请输入用户名"/>
+ <input v-model="loginForm.password" class="u-border-bottom" type="password" placeholder="请输入密码"/>
<button class="login-btn" :style="[inputStyle]" @tap="submit">
- 登录 <text class="i-mdi-login" />
+ 登录
+ <text class="i-mdi-login"/>
</button>
-
- <view class="alternative">
- <view class="password"> 密码登录 </view>
- <view class="issue flex items-center">
- 遇到问题 <text class="i-mdi-help" />
- </view>
- </view>
- </view>
- <view class="login-type-wrap">
- <view class="item wechat">
- <view class="icon">
- <u-icon size="35" name="weixin-fill" color="rgb(83,194,64)" />
- </view>
- 微信
- </view>
- <view class="item QQ">
- <view class="icon">
- <u-icon size="35" name="qq-fill" color="rgb(17,183,233)" />
- </view>
- QQ
- </view>
- </view>
- <view class="hint">
- 登录代表同意
- <text class="link"> 用户协议、隐私政策, </text>
- 并授权使用您的账号信息(如昵称、头像、收获地址)以便您统一管理
</view>
</view>
</template>
<script setup>
- import md5 from 'js-md5'
- import {
- loginByUsername
- } from '@/api/user/index.js'
- import {
- HOME_PATH,
- isTabBarPath,
- LOGIN_PATH,
- removeQueryString,
- } from "@/router";
- import {
- setToken
- } from "@/utils/auth";
- // import { useUserStore } from '@/store';
-
- // const userStore = useUserStore();
- const tel = ref("18502811111");
- const code = ref("1234");
- const tips = ref();
- const uCodeRef = ref(null);
- let redirect = HOME_PATH;
-
- const inputStyle = computed(() => {
- const style = {};
- if (tel.value && code.value) {
- style.color = "#fff";
- style.backgroundColor = uni.$u.color.warning;
- }
- return style;
- });
-
- function codeChange(text) {
- tips.value = text;
+import md5 from 'js-md5'
+import {loginByUsername} from '@/api/user/index.js'
+import {useUserStore} from "@/store/index.js";
+import {
+ HOME_PATH, LOGIN_PATH, removeQueryString,
+} from "@/router";
+const userStore = useUserStore();
+const loginForm = ref({
+ username: "shuishen",
+ password: "Dashabi...."
+})
+const inputStyle = computed(() => {
+ const style = {};
+ if (loginForm.value.username && loginForm.value.password) {
+ style.color = "#fff";
+ style.backgroundColor = uni.$u.color.warning;
}
+ return style;
+});
+let redirect = HOME_PATH;
- function getCode() {
- if (uCodeRef.value?.canGetCode) {
- // 模拟向后端请求验证码
- uni.showLoading({
- title: "正在获取验证码",
- });
- setTimeout(() => {
- uni.hideLoading();
- uni.$u.toast("验证码已发送");
- // 通知验证码组件内部开始倒计时
- uCodeRef.value?.start();
- }, 1000);
- } else {
- uni.$u.toast("倒计时结束后再发送");
- }
+async function submit() {
+ let userInfo = {
+ "tenantId": "000000",
+ "deptId": "",
+ "roleId": "",
+ "username": loginForm.value.username,
+ "password": loginForm.value.password,
+ "type": "account",
+ "code": "",
+ "key": "",
}
- async function submit() {
- if (!uni.$u.test.mobile(Number(tel.value))) {
- uni.$u.toast("请输入正确的手机号");
- return;
- }
- if (!code.value) {
- uni.$u.toast("请输入验证码");
- return;
- }
- // 登录请求
- // const res = await userStore.login({ phone: tel.value, code: code.value }).catch(() => {
- // uni.$u.toast('登录失败');
- // });
- // if (!res) return;
- setToken("1234567890");
- setTimeout(() => {
- uni.$u.route({
- type: isTabBarPath(redirect) ? "switchTab" : "redirectTo",
- url: redirect,
- });
- }, 800);
-
- let userInfo = {
- "tenantId": "000000",
- "deptId": "",
- "roleId": "",
- "username": "shuishen",
- "password": "Dashabi....",
- "type": "account",
- "code": "",
- "key": "",
- "image": "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
- }
-
- loginByUsername(
- userInfo.tenantId,
- userInfo.deptId,
- userInfo.roleId,
- userInfo.username,
- md5(userInfo.password),
- userInfo.type,
- userInfo.key,
- userInfo.code
- ).then(res => {
- uni.switchTab({
- url: '/pages/map/index'
- })
+ loginByUsername(
+ userInfo.tenantId,
+ userInfo.deptId,
+ userInfo.roleId,
+ userInfo.username,
+ md5(userInfo.password),
+ userInfo.type,
+ userInfo.key,
+ userInfo.code
+ ).then(res => {
+ userStore.setUserInfo(res.data)
+ uni.switchTab({
+ url: '/pages/user/index'
})
- }
+ })
+}
- onLoad((options) => {
- if (options.redirect && removeQueryString(options.redirect) !== LOGIN_PATH) {
- redirect = decodeURIComponent(options.redirect);
- }
- });
+onLoad((options) => {
+ if (options.redirect && removeQueryString(options.redirect) !== LOGIN_PATH) {
+ redirect = decodeURIComponent(options.redirect);
+ }
+});
</script>
<style lang="scss" scoped>
- .login-form-wrap {
- @apply mt-80rpx mx-auto mb-0 w-600rpx;
+.login-form-wrap {
+ @apply mt-80rpx mx-auto mb-0 w-600rpx;
- .title {
- @apply mb-100rpx text-60rpx text-left font-500;
- }
-
- input {
- @apply pb-6rpx mb-10rpx text-left;
- }
-
- .tips {
- @apply mt-8rpx mb-60rpx;
-
- color: $u-info;
- }
-
- .login-btn {
- @apply flex items-center justify-center py-12rpx px-0 text-30rpx bg-#fdf3d0 border-none;
-
- color: $u-tips-color;
-
- &::after {
- @apply border-none;
- }
- }
-
- .alternative {
- @apply flex justify-between mt-30rpx;
-
- color: $u-tips-color;
- }
+ .title {
+ @apply mb-100rpx text-60rpx text-left font-500;
}
- .login-type-wrap {
- @apply flex justify-between pt-350rpx px-150rpx pb-150rpx;
-
- .item {
- @apply flex items-center flex-col text-28rpx;
-
- color: $u-content-color;
- }
+ input {
+ @apply pb-6rpx mb-10rpx text-left;
}
- .hint {
- @apply px-40rpx py-20rpx text-24rpx;
+ .tips {
+ @apply mt-8rpx mb-60rpx;
+
+ color: $u-info;
+ }
+
+ .login-btn {
+ @apply flex items-center justify-center py-12rpx px-0 text-30rpx bg-#fdf3d0 border-none;
color: $u-tips-color;
- .link {
- color: $u-warning;
+ &::after {
+ @apply border-none;
}
}
+
+ .alternative {
+ @apply flex justify-between mt-30rpx;
+
+ color: $u-tips-color;
+ }
+}
+
+.login-type-wrap {
+ @apply flex justify-between pt-350rpx px-150rpx pb-150rpx;
+
+ .item {
+ @apply flex items-center flex-col text-28rpx;
+
+ color: $u-content-color;
+ }
+}
+
+.hint {
+ @apply px-40rpx py-20rpx text-24rpx;
+
+ color: $u-tips-color;
+
+ .link {
+ color: $u-warning;
+ }
+}
</style>
diff --git a/src/pages/map/index.vue b/src/pages/map/index.vue
index 298de8b..1fa6657 100644
--- a/src/pages/map/index.vue
+++ b/src/pages/map/index.vue
@@ -6,18 +6,15 @@
<script setup>
onShow(() => {
- console.log(222);
// #ifdef APP-PLUS
- console.log(111);
- plus.screen.lockOrientation("landscape-primary");
+ // plus.screen.lockOrientation("landscape-primary");
// #endif
});
onHide(() => {
- console.log(123123);
// #ifdef APP-PLUS
- plus.screen.lockOrientation("portrait-primary");
+ // plus.screen.lockOrientation("portrait-primary");
// #endif
});
</script>
diff --git a/src/pages/user/index.vue b/src/pages/user/index.vue
index 5f1bce3..db188fe 100644
--- a/src/pages/user/index.vue
+++ b/src/pages/user/index.vue
@@ -1,63 +1,62 @@
<!-- 我的 -->
<template>
<view class="page-wrap">
- <u-navbar title="" placeholder left-icon="" right-icon="camera-fill" />
+ <u-navbar title="" placeholder left-icon="" right-icon="camera-fill"/>
<view class="flex items-center pb-30rpx pl-30rpx pr-20rpx">
<view class="mr-10rpx">
- <u-avatar src="/static/images/logo.png" size="70" />
+ <u-avatar src="/static/images/logo.png" size="70"/>
</view>
<view class="flex-1">
- <view class="pb-20rpx text-36rpx"> uni-app </view>
+ <view class="pb-20rpx text-36rpx">{{ userStore.$state?.userInfo?.nick_name }}</view>
<view class="u-tips-color text-28rpx" @click="toCopy">
- 微信号:uni-app
+ ID:{{ userStore.$state?.userInfo?.user_id }}
</view>
</view>
<view class="ml-10rpx p-10rpx">
- <u-icon name="scan" color="#969799" />
+ <u-icon name="scan" color="#969799"/>
</view>
<view class="ml-10rpx p-10rpx">
- <u-icon name="arrow-right" color="#969799" />
+ <u-icon name="arrow-right" color="#969799"/>
</view>
</view>
<view class="mt-20rpx">
<u-cell-group>
- <u-cell icon="rmb-circle" title="支付" is-link />
- </u-cell-group>
- </view>
-
- <view class="mt-20rpx">
- <u-cell-group>
- <u-cell icon="star" title="收藏" is-link />
- <u-cell icon="photo" title="相册" is-link />
- <u-cell icon="coupon" title="卡券" is-link />
- <u-cell icon="heart" title="关注" is-link />
- </u-cell-group>
- </view>
-
- <view class="mt-20rpx">
- <u-cell-group>
- <u-cell icon="setting" title="设置" is-link />
+ <u-cell icon="setting" title="退出登录" is-link @click="logOut"/>
</u-cell-group>
</view>
</view>
</template>
<script setup>
-import { useClipboard, usePermission } from "@/hooks";
+import {useClipboard} from "@/hooks";
+import {useUserStore} from "@/store/index.js";
+import {onShow} from "@dcloudio/uni-app";
+import {getDeviceRegionApi} from "@/api/map.js";
-const { setClipboardData, getClipboardData } = useClipboard();
-
+const {setClipboardData, getClipboardData} = useClipboard();
+const userStore = useUserStore();
// 复制
const toCopy = async () => {
- await setClipboardData({ data: "1234567890" });
+ await setClipboardData({data: "1234567890"});
const data = await getClipboardData();
- console.log("[ data ] >", data);
};
+
+function logOut() {
+ userStore.setUserInfo(null)
+ uni.redirectTo({
+ url: '/pages/login/index'
+ })
+}
+
+function getDeviceRegion() {
+ getDeviceRegionApi().then(res =>{
+ console.log(res.data.data,'用户设备')
+ })
+}
// 登录鉴权,微信小程序端点击tabbar的底层逻辑不触发uni.switchTab,需要在页面onShow生命周期中校验权限
onShow(async () => {
- const hasPermission = await usePermission();
- console.log(hasPermission ? "已登录" : "未登录,拦截跳转");
+ getDeviceRegion()
});
</script>
diff --git a/src/pages/work/index.vue b/src/pages/work/index.vue
index 110e945..8682ae9 100644
--- a/src/pages/work/index.vue
+++ b/src/pages/work/index.vue
@@ -39,7 +39,7 @@
// 分享使用示例
const { onShareAppMessage, onShareTimeline } = useShare({
title: "首页",
- path: "pages/tab/home/index",
+ path: "pages/tab/map/index",
imageUrl: "",
});
onShareAppMessage();
diff --git a/src/plugins/permission.js b/src/plugins/permission.js
index 4e871c3..0700fc8 100644
--- a/src/plugins/permission.js
+++ b/src/plugins/permission.js
@@ -5,7 +5,7 @@
removeQueryString,
routes
} from "@/router"
-import { isLogin } from "@/utils/auth"
+import {useUserStore} from "@/store/index.js";
// 白名单路由
const whiteList = ["/"]
@@ -28,7 +28,7 @@
return false
}
// 在白名单中或有token,直接放行
- const hasPermission = whiteList.includes(removeQueryString(path)) || isLogin()
+ const hasPermission = whiteList.includes(removeQueryString(path)) || useUserStore().$state.userInfo.access_token
if (!hasPermission) {
// 将用户的目标路径传递过去,这样可以实现用户登录之后,直接跳转到目标页面
uni.redirectTo({
diff --git a/src/router/index.js b/src/router/index.js
index 1ba368a..41ec59c 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -4,21 +4,21 @@
* @LastEditors : yuan
* @LastEditTime : 2025-09-28 09:55:05
* @FilePath : \src\router\index.js
- * @Description :
- * Copyright 2025 OBKoro1, All Rights Reserved.
+ * @Description :
+ * Copyright 2025 OBKoro1, All Rights Reserved.
* 2025-09-28 09:31:16
*/
import pagesJson from "@/pages.json"
// 路径常量
-export const HOME_PATH = "/pages/tab/home/index"
-export const LOGIN_PATH = "/pages/common/login/index"
+export const HOME_PATH = "/pages/map/index"
+export const LOGIN_PATH = "/pages/login/index"
export const ERROR404_PATH = "/pages/common/404/index"
/**
* 解析路由地址
* @param {object} pagesJson
- * @returns [{"path": "/pages/tab/home/index","needLogin": false},...]
+ * @returns [{"path": "/pages/tab/map/index","needLogin": false},...]
*/
function parseRoutes (pagesJson = {}) {
if (!pagesJson.pages) {
diff --git a/src/store/modules/user/index.js b/src/store/modules/user/index.js
index a04baa1..67dfd9c 100644
--- a/src/store/modules/user/index.js
+++ b/src/store/modules/user/index.js
@@ -1,87 +1,23 @@
-/*
- * @Author : yuan
- * @Date : 2025-09-28 09:31:16
- * @LastEditors : yuan
- * @LastEditTime : 2025-09-28 10:02:26
- * @FilePath : \src\store\modules\user\index.ts
- * @Description :
- * Copyright 2025 OBKoro1, All Rights Reserved.
- * 2025-09-28 09:31:16
- */
-import { defineStore } from 'pinia'
-import { UserApi } from '@/api'
-import { clearToken, setToken } from '@/utils/auth'
+import {defineStore} from 'pinia'
const useUserStore = defineStore('user', {
state: () => ({
- user_id: '',
- user_name: '江阳小道',
- avatar: '',
- token: ''
+ userInfo: null // 用户信息
}),
- getters: {
- userInfo (state) {
- return { ...state }
- }
- },
actions: {
- // 设置用户的信息
- setInfo (partial) {
- this.$patch(partial)
+ setUserInfo(userInfo) {
+ this.userInfo = userInfo
},
- // 重置用户信息
- resetInfo () {
+ // 重置
+ resetUserStore() {
this.$reset()
},
- // 获取用户信息
- async info () {
- const result = await UserApi.profile()
- this.setInfo(result)
+ // 合并
+ mergeUserStore(data) {
+ this.$patch(data)
},
- // 异步登录并存储token
- login (loginForm) {
- return new Promise((resolve, reject) => {
- UserApi.login(loginForm)
- .then((res) => {
- const token = res.token
- if (token) {
- setToken(token)
- }
- resolve(res)
- })
- .catch((error) => {
- reject(error)
- })
- })
- },
- // Logout
- async logout () {
- await UserApi.logout()
- this.resetInfo()
- clearToken()
- },
- // 小程序授权登录
- authLogin (provider = 'weixin') {
- return new Promise((resolve, reject) => {
- uni.login({
- provider,
- success: async (result) => {
- if (result.code) {
- const res = await UserApi.loginByCode({ code: result.code })
- resolve(res)
- } else {
- reject(new Error(result.errMsg))
- }
- },
- fail: (err) => {
- console.error(`login error: ${err}`)
- reject(err)
- }
- })
- })
- }
},
- persist: true
+ persist: true //持久化
})
export default useUserStore
diff --git a/src/utils/auth/index.js b/src/utils/auth/index.js
deleted file mode 100644
index 73400ed..0000000
--- a/src/utils/auth/index.js
+++ /dev/null
@@ -1,15 +0,0 @@
-const TokenKey = "admin-token"
-const TokenPrefix = "Bearer "
-function isLogin () {
- return !!uni.getStorageSync(TokenKey)
-}
-function getToken () {
- return uni.getStorageSync(TokenKey)
-}
-function setToken (token) {
- uni.setStorageSync(TokenKey, token)
-}
-function clearToken () {
- uni.removeStorageSync(TokenKey)
-}
-export { clearToken, getToken, isLogin, setToken, TokenPrefix }
diff --git a/src/utils/index.js b/src/utils/index.js
index 5b406d6..4b01129 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -8,7 +8,6 @@
* Copyright 2025 OBKoro1, All Rights Reserved.
* 2025-09-28 09:31:16
*/
-export * from "./auth"
export * from "./common"
export * from "./modals"
export * from "./request"
diff --git a/src/utils/request/index.js b/src/utils/request/index.js
index 1e82acf..53652c7 100644
--- a/src/utils/request/index.js
+++ b/src/utils/request/index.js
@@ -3,6 +3,20 @@
const http = new Request()
+export function request (config) {
+ return new Promise((resolve, reject) => {
+ http
+ .request(config)
+ .then(res => {
+ resolve(res)
+ })
+ .catch(err => {
+ reject(err)
+ })
+ })
+}
+
+
// 引入拦截器配置
export function setupRequest () {
http.setConfig(defaultConfig => {
@@ -19,21 +33,8 @@
responseInterceptors(http)
}
-export function request (config) {
- return new Promise((resolve, reject) => {
- http
- .request(config)
- .then(res => {
- console.log("[ res ] >", res)
- const { result } = res.data
- resolve(result)
- })
- .catch(err => {
- console.error("[ err ] >", err)
- reject(err)
- })
- })
-}
+
+
export function get (url, config) {
return request({ ...config, url, method: "GET" })
diff --git a/src/utils/request/interceptors.js b/src/utils/request/interceptors.js
index 0a45b3b..22c8616 100644
--- a/src/utils/request/interceptors.js
+++ b/src/utils/request/interceptors.js
@@ -1,9 +1,6 @@
import {
useUserStore
} from "@/store"
-import {
- getToken
-} from "@/utils/auth"
import storage from "@/utils/storage"
import {
showMessage
@@ -12,8 +9,6 @@
import {
Base64
} from 'js-base64'
-// 重试队列,每一项将是一个待执行的函数形式
-let requestQueue = []
// 防止重复提交
const repeatSubmit = config => {
@@ -45,107 +40,48 @@
}
}
-// 是否正在刷新token的标记
-let isRefreshing = false
-
-// 刷新token
-const refreshToken = async (http, config) => {
- // 是否在获取token中,防止重复获取
- if (!isRefreshing) {
- // 修改登录状态为true
- isRefreshing = true
- // 等待登录完成
- await useUserStore().authLogin()
- // 登录完成之后,开始执行队列请求
- requestQueue.forEach(cb => cb())
- // 重试完了清空这个队列
- requestQueue = []
- isRefreshing = false
- // 重新执行本次请求
- return http.request(config)
- }
-
- return new Promise(resolve => {
- // 将resolve放进队列,用一个函数形式来保存,等登录后直接执行
- requestQueue.push(() => {
- resolve(http.request(config))
- })
- })
-}
-
+// 请求拦截器
function requestInterceptors(http) {
- http.interceptors.request.use((config) => { // 可使用async await 做异步操作
+
+ http.interceptors.request.use((config) => {
+ const {detail} = useUserStore().$state?.userInfo || {}
// 假设有token值需要在头部需要携带
- let accessToken = uni.getStorageSync('accessToken');
+ let accessToken = useUserStore()?.$state?.userInfo?.access_token;
if (accessToken) {
config.header['Blade-Auth'] = 'bearer ' + accessToken;
}
-
+ if (detail?.areaCode) {
+ config.header['areaCode'] = detail.areaCode
+ }
// 安全请求header
config.header['Blade-Requested-With'] = 'BladeHttpRequest';
// 客户端认证参数
config.header['Authorization'] = 'Basic ' + Base64.encode(website.clientId + ':' + website.clientSecret);
-
- // #ifndef H5
- let url = config.url
- if (process.env.NODE_ENV == 'development' && !url.startsWith("http")) {
- url = url.substring(url.indexOf('/api') + 4)
- config.url = url
- }
- // #endif
-
- // 额外参数
- // config.data = config.data || {};
- // config.data.pf = uni.getSystemInfoSync().platform;
- // config.data.sys = uni.getSystemInfoSync().system;
-
- // 演示custom 用处
- // if (config.custom.auth) {
- // config.header.token = 'token'
- // }
- // if (config.custom.loading) {
- // uni.showLoading()
- // }
- /**
- /* 演示
- if (!token) { // 如果token不存在,return Promise.reject(config) 会取消本次请求
- return Promise.reject(config)
- }
- **/
return config
}, config => { // 可使用async await 做异步操作
return Promise.reject(config)
})
}
+// 响应拦截器
function responseInterceptors(http) {
http.interceptors.response.use((response) => {
- console.log(response, 2222)
- // 若有数据返回则通过
- if (response.data.access_token || response.data.key) {
- return response.data
- }
- // 服务端返回的状态码不等于200,则reject()
- if (response.data.code !== 200) {
- uni.showToast({
- title: response.data.msg,
- icon: 'none'
- });
+ let res = response
+ const status = res.data.error_code || res.data.code || res.statusCode
+ const message = res?.data?.msg || res?.data?.error_description || res?.data?.message || '系统错误'
+ if (status !== 200) {
+ uni.showToast({title: message, icon: 'none'});
return Promise.reject(response);
}
- return response.data;
+ return response;
}, (response) => {
- console.log(response, 111)
/* 对响应错误做点什么 (statusCode !== 200)*/
- uni.showToast({
- title: response.data.msg,
- icon: 'none'
- });
- if (response.statusCode == 401) {
+ uni.showToast({title: response?.data?.msg, icon: 'none'});
+ if (response.statusCode === 401) {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
uni.redirectTo({
- url: `/pages/login/login-account?redirect=/${currentPage.route}`
+ url: `/pages/login/index?redirect=/${currentPage.route}`
})
}
return Promise.reject(response)
--
Gitblit v1.9.3