From f6b35cc0747c152f24014773018f0724139101e8 Mon Sep 17 00:00:00 2001 From: Vinjor Date: Wed, 19 Mar 2025 15:39:32 +0800 Subject: [PATCH] 1 --- api/login.js | 16 ++++ api/system/config.js | 12 +++ config.js | 8 +- main.js | 1 - manifest.json | 6 +- package.json | 8 ++ pages.json | 17 ++-- pages/common/richview/index.vue | 62 ++++++++++++++ pages/login.vue | 145 +++++++++++++++++++++++--------- permission.js | 4 +- store/modules/user.js | 17 +++- utils/request.js | 4 +- 12 files changed, 240 insertions(+), 60 deletions(-) create mode 100644 api/system/config.js create mode 100644 package.json create mode 100644 pages/common/richview/index.vue diff --git a/api/login.js b/api/login.js index 6ce7e7c..48a11a6 100644 --- a/api/login.js +++ b/api/login.js @@ -1,5 +1,21 @@ import request from '@/utils/request' +// 微信登录授权 +export function wxLogin(code, encryptedIv, encryptedData) { + const data = { + code, + encryptedIv, + encryptedData + } + return request({ + 'url': '/wxLogin', + headers: { + isToken: false + }, + 'method': 'post', + 'data': data + }) +} // 登录方法 export function login(username, password, code, uuid) { const data = { diff --git a/api/system/config.js b/api/system/config.js new file mode 100644 index 0000000..db76c9c --- /dev/null +++ b/api/system/config.js @@ -0,0 +1,12 @@ +import request from '@/utils/request' + + +// 查询站点配置 +export function getSiteConfig(params) { + return request({ + url: '/base/config/getConfigByCode', + method: 'get', + params:params + }) +} + diff --git a/config.js b/config.js index 33b90d5..491a990 100644 --- a/config.js +++ b/config.js @@ -1,6 +1,6 @@ // 应用全局配置 module.exports = { - baseUrl: 'http://127.0.0.1/dev-api', + baseUrl: 'http://192.168.1.17:8080', // baseUrl: 'http://localhost:8080', // 应用信息 appInfo: { @@ -12,12 +12,12 @@ module.exports = { logo: "/static/logo.png", // 政策协议 agreements: [{ - title: "隐私政策", - url: "https://ruoyi.vip/protocol.html" + title: "隐私协议", + code: "privacy_agreement" }, { title: "用户服务协议", - url: "https://ruoyi.vip/protocol.html" + code: "privacy_agreement" } ] } diff --git a/main.js b/main.js index 3985b1b..961b30a 100644 --- a/main.js +++ b/main.js @@ -7,7 +7,6 @@ Vue.use(plugins) Vue.config.productionTip = false Vue.prototype.$store = store - App.mpType = 'app' const app = new Vue({ diff --git a/manifest.json b/manifest.json index 8a86db5..b9e2ab0 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { - "name" : "若依移动端", - "appid" : "__UNI__25A9D80", + "name" : "多点通告", + "appid" : "__UNI__5491739", "description" : "", "versionName" : "1.1.0", "versionCode" : "100", @@ -41,7 +41,7 @@ }, "quickapp" : {}, "mp-weixin" : { - "appid" : "wxccd7e2a0911b3397", + "appid" : "wxd8ef44a8268672e4", "setting" : { "urlCheck" : false, "es6" : false, diff --git a/package.json b/package.json new file mode 100644 index 0000000..f87b47d --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "rich-text-parser": "^1.0.2" + }, + "devDependencies": { + "rich-text-parser": "^1.0.2" + } +} diff --git a/pages.json b/pages.json index 333251c..d0c4096 100644 --- a/pages.json +++ b/pages.json @@ -1,5 +1,11 @@ { "pages": [{ + "path": "pages/index", + "style": { + "navigationBarTitleText": "首页", + "navigationStyle": "custom" + } + }, { "path": "pages/login", "style": { "navigationBarTitleText": "登录" @@ -9,12 +15,6 @@ "style": { "navigationBarTitleText": "注册" } - }, { - "path": "pages/index", - "style": { - "navigationBarTitleText": "若依移动端框架", - "navigationStyle": "custom" - } }, { "path": "pages/work/index", "style": { @@ -70,6 +70,11 @@ "style": { "navigationBarTitleText": "浏览文本" } + }, { + "path": "pages/common/richview/index", + "style": { + "navigationBarTitleText": "浏览富文本" + } }], "tabBar": { "color": "#000000", diff --git a/pages/common/richview/index.vue b/pages/common/richview/index.vue new file mode 100644 index 0000000..f2aa81c --- /dev/null +++ b/pages/common/richview/index.vue @@ -0,0 +1,62 @@ + + + + + diff --git a/pages/login.vue b/pages/login.vue index 7f0e8c8..7491462 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -1,40 +1,42 @@ @@ -54,26 +56,27 @@ password: "admin123", code: "", uuid: '' + }, + //微信登录 + wxLoginForm: { + code: "", + encryptedIv: "", + encryptedData: "" } } }, created() { this.getCode() + this.wxLogin() }, methods: { // 用户注册 handleUserRegister() { this.$tab.redirectTo(`/pages/register`) }, - // 隐私协议 - handlePrivacy() { - let site = this.globalConfig.appInfo.agreements[0] - this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`) - }, - // 用户协议 - handleUserAgrement() { - let site = this.globalConfig.appInfo.agreements[1] - this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`) + // 查看相关协议 + handleUserAgrement(site) { + this.$tab.navigateTo(`/pages/common/richview/index?title=${site.title}&code=${site.code}`) }, // 获取图形验证码 getCode() { @@ -85,6 +88,55 @@ } }) }, + wxLogin() { + let that = this + uni.login({ + provider: 'weixin', + success(res) { + console.log(543, res); + if (res.code) { + that.wxLoginForm.code= res.code + } else { + console.log('登录失败!' + res.errMsg) + } + } + }) + }, + //微信授权登录 + getPhone(e) { + console.log("微信小程序发起授权登录") + this.$modal.loading("登录中...") + uni.checkSession({ + success: () => { + this.wxLoginForm.encryptedIv = e.detail.iv + this.wxLoginForm.encryptedData = e.detail.encryptedData + this.sendWxLoginFormToLocalService() + }, + fail: () => { + uni.showToast({ + icon: 'error', + duration: 2000, + title: "登录状态过期,重新登录" + }); + } + }) + }, + //向后端发起登录请求 + sendWxLoginFormToLocalService(){ + this.$store.dispatch('WxLogin', this.wxLoginForm).then(() => { + this.$modal.closeLoading() + this.loginSuccess() + }).catch((e) => { + uni.showToast({ + icon: 'error', + duration: 2000, + title: e + }); + // if (this.captchaEnabled) { + // // this.getCode() + // } + }) + }, // 登录方法 async handleLogin() { if (this.loginForm.username === "") { @@ -94,7 +146,7 @@ } else if (this.loginForm.code === "" && this.captchaEnabled) { this.$modal.msgError("请输入验证码") } else { - this.$modal.loading("登录中,请耐心等待...") + this.$modal.loading("登录中...") this.pwdLogin() } }, @@ -124,7 +176,18 @@ page { background-color: #ffffff; } - + .dl{ + width: 90%; + height: 44px; + background-color: #0D2E8D; + border-radius: 50px; + margin: 0 auto; + font-size: 16px; + color: #FFFFFF; + display: flex; + justify-content: center; + align-items: center; + } .normal-login-container { width: 100%; @@ -175,20 +238,20 @@ margin-top: 40px; height: 45px; } - + .reg { margin-top: 15px; } - + .xieyi { color: #333; margin-top: 20px; } - + .login-code { height: 38px; float: right; - + .login-code-img { height: 38px; position: absolute; diff --git a/permission.js b/permission.js index cbaec53..9b9f3ac 100644 --- a/permission.js +++ b/permission.js @@ -2,10 +2,10 @@ import { getToken } from '@/utils/auth' // 登录页面 const loginPage = "/pages/login" - + // 页面白名单 const whiteList = [ - '/pages/login', '/pages/register', '/pages/common/webview/index' + '/pages/login', '/pages/register', '/pages/common/webview/index','/pages/common/richview/index' ] // 检查地址白名单 diff --git a/store/modules/user.js b/store/modules/user.js index c1ec441..d657606 100644 --- a/store/modules/user.js +++ b/store/modules/user.js @@ -1,7 +1,7 @@ import config from '@/config' import storage from '@/utils/storage' import constant from '@/utils/constant' -import { login, logout, getInfo } from '@/api/login' +import { login,wxLogin, logout, getInfo } from '@/api/login' import { getToken, setToken, removeToken } from '@/utils/auth' const baseUrl = config.baseUrl @@ -38,6 +38,21 @@ const user = { }, actions: { + // 微信登录 + WxLogin({ commit }, wxUserInfo) { + const code = wxUserInfo.code + const encryptedIv = wxUserInfo.encryptedIv + const encryptedData = wxUserInfo.encryptedData + return new Promise((resolve, reject) => { + wxLogin(code, encryptedIv, encryptedData).then(res => { + setToken(res.token) + commit('SET_TOKEN', res.token) + resolve() + }).catch(error => { + reject(error) + }) + }) + }, // 登录 Login({ commit }, userInfo) { const username = userInfo.username.trim() diff --git a/utils/request.js b/utils/request.js index 860f0ef..110816d 100644 --- a/utils/request.js +++ b/utils/request.js @@ -48,10 +48,10 @@ const request = config => { reject('无效的会话,或者会话已过期,请重新登录。') } else if (code === 500) { toast(msg) - reject('500') + reject(msg) } else if (code !== 200) { toast(msg) - reject(code) + reject(msg) } resolve(res.data) })