1
This commit is contained in:
parent
ab431485db
commit
f6b35cc074
16
api/login.js
16
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 = {
|
||||
|
12
api/system/config.js
Normal file
12
api/system/config.js
Normal file
@ -0,0 +1,12 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
|
||||
// 查询站点配置
|
||||
export function getSiteConfig(params) {
|
||||
return request({
|
||||
url: '/base/config/getConfigByCode',
|
||||
method: 'get',
|
||||
params:params
|
||||
})
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
1
main.js
1
main.js
@ -7,7 +7,6 @@ Vue.use(plugins)
|
||||
|
||||
Vue.config.productionTip = false
|
||||
Vue.prototype.$store = store
|
||||
|
||||
App.mpType = 'app'
|
||||
|
||||
const app = new Vue({
|
||||
|
@ -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,
|
||||
|
8
package.json
Normal file
8
package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"rich-text-parser": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rich-text-parser": "^1.0.2"
|
||||
}
|
||||
}
|
17
pages.json
17
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",
|
||||
|
62
pages/common/richview/index.vue
Normal file
62
pages/common/richview/index.vue
Normal file
@ -0,0 +1,62 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<div class="body">
|
||||
<rich-text style="width: 100%" :nodes="richTextHtml" />
|
||||
</div>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getSiteConfig } from '@/api/system/config'
|
||||
import parser from 'rich-text-parser'
|
||||
export default {
|
||||
filters: {
|
||||
formatRichText(html) { // 控制小程序中图片大小
|
||||
// console.log(html)
|
||||
const nodes = parser.getRichTextJson(html)
|
||||
return nodes.children
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
richTextHtml: '',
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
uni.setNavigationBarTitle({
|
||||
title: options.title
|
||||
})
|
||||
this.getRichTextHtml(options.code)
|
||||
},
|
||||
methods:{
|
||||
async getRichTextHtml(code){
|
||||
let that = this
|
||||
getSiteConfig({code:code}).then(res => {
|
||||
let json = JSON.parse(res.data)
|
||||
that.richTextHtml = json[0].value
|
||||
}).catch((e) => {
|
||||
uni.showToast({
|
||||
icon: 'error',
|
||||
duration: 2000,
|
||||
title: e
|
||||
});
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.container {
|
||||
height: 100%;
|
||||
padding: 20rpx;
|
||||
background: white;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.body{
|
||||
flex: 1;
|
||||
height: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
145
pages/login.vue
145
pages/login.vue
@ -1,40 +1,42 @@
|
||||
<template>
|
||||
<view class="normal-login-container">
|
||||
<view class="logo-content align-center justify-center flex">
|
||||
<image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
|
||||
</image>
|
||||
<text class="title">若依移动端登录</text>
|
||||
<!-- <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">-->
|
||||
<!-- </image>-->
|
||||
<text class="title">请登录</text>
|
||||
</view>
|
||||
<view class="login-form-content">
|
||||
<view class="input-item flex align-center">
|
||||
<view class="iconfont icon-user icon"></view>
|
||||
<input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
|
||||
</view>
|
||||
<view class="input-item flex align-center">
|
||||
<view class="iconfont icon-password icon"></view>
|
||||
<input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
|
||||
</view>
|
||||
<view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
|
||||
<view class="iconfont icon-code icon"></view>
|
||||
<input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
|
||||
<view class="login-code">
|
||||
<image :src="codeUrl" @click="getCode" class="login-code-img"></image>
|
||||
</view>
|
||||
</view>
|
||||
<!-- <view class="input-item flex align-center">-->
|
||||
<!-- <view class="iconfont icon-user icon"></view>-->
|
||||
<!-- <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />-->
|
||||
<!-- </view>-->
|
||||
<!-- <view class="input-item flex align-center">-->
|
||||
<!-- <view class="iconfont icon-password icon"></view>-->
|
||||
<!-- <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />-->
|
||||
<!-- </view>-->
|
||||
<!-- <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">-->
|
||||
<!-- <view class="iconfont icon-code icon"></view>-->
|
||||
<!-- <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />-->
|
||||
<!-- <view class="login-code"> -->
|
||||
<!-- <image :src="codeUrl" @click="getCode" class="login-code-img"></image>-->
|
||||
<!-- </view>-->
|
||||
<!-- </view>-->
|
||||
<view class="action-btn">
|
||||
<button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
|
||||
</view>
|
||||
<view class="reg text-center" v-if="register">
|
||||
<text class="text-grey1">没有账号?</text>
|
||||
<text @click="handleUserRegister" class="text-blue">立即注册</text>
|
||||
<button open-type="getPhoneNumber" @getphonenumber="getPhone" class="login-btn cu-btn block bg-blue lg round">手机号快捷登录</button>
|
||||
<!-- <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>-->
|
||||
<!-- <u-button open-type='getPhoneNumber' text="手机号快捷登录" @getphonenumber="wxHandleLogin" class="login-btn cu-btn block bg-green lg round"></u-button>-->
|
||||
</view>
|
||||
<!-- <view class="reg text-center" v-if="register">-->
|
||||
<!-- <text class="text-grey1">没有账号?</text>-->
|
||||
<!-- <text @click="handleUserRegister" class="text-blue">立即注册</text>-->
|
||||
<!-- </view>-->
|
||||
<view class="xieyi text-center">
|
||||
<text class="text-grey1">登录即代表同意</text>
|
||||
<text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
|
||||
<text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
|
||||
<text @click="handleUserAgrement(globalConfig.appInfo.agreements[0])" class="text-blue">《{{globalConfig.appInfo.agreements[0].title}}》</text>
|
||||
<text @click="handleUserAgrement(globalConfig.appInfo.agreements[1])" class="text-blue">《{{ globalConfig.appInfo.agreements[1].title }}》</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -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;
|
||||
|
@ -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'
|
||||
]
|
||||
|
||||
// 检查地址白名单
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user