Browse Source

框架完善

master
yxq 2 months ago
parent
commit
7d87b51cba
9 changed files with 85 additions and 139 deletions
  1. +4
    -80
      monitorMobile/api/user.js
  2. +44
    -9
      monitorMobile/common/mixins.vue
  3. +4
    -7
      monitorMobile/common/setting.js
  4. +2
    -22
      monitorMobile/http/api.js
  5. +1
    -1
      monitorMobile/http/config.js
  6. +1
    -3
      monitorMobile/main.js
  7. +21
    -8
      monitorMobile/pages/login.vue
  8. +0
    -1
      monitorMobile/store/$u.mixin.js
  9. +8
    -8
      monitorMobile/store/index.js

+ 4
- 80
monitorMobile/api/user.js View File

@@ -1,85 +1,9 @@
import http from '@/http/api.js' import http from '@/http/api.js'
// 获取token
export const token = (tenantId, username, password, type) => {
// 登录
export const login = (data) => {
return http.request({ return http.request({
url: '/api/blade-auth/oauth/token',
url: '/api/sys/auth/b/login',
method: 'POST', method: 'POST',
header: {
'Tenant-Id': tenantId
},
params: {
tenantId,
username,
password,
grant_type: "password",
scope: "all",
type
}
})
}
export const getTenantId = (params) => {
return http.request({
url: '/api/blade-auth/oauth/getTenantId',
method: 'get',
params: {
...params
}
})
}

export const refreshToken = (refresh_token, tenantId) => {
return http.request({
url: '/api/blade-auth/oauth/token',
method: 'post',
header: {
'Tenant-Id': tenantId
},
params: {
tenantId,
refresh_token,
grant_type: "refresh_token",
scope: "all",
}
})
}

// 获取用户信息
export const userInfo = () => {
return http.request({
url: '/api/blade-user/info',
method: 'GET',
})
}

// 获取用户信息
export const getUser = (id) => {
return http.request({
url: '/api/blade-user/detail',
method: 'GET',
params: { id }
})
}
/* 修改用户信息 */
export const updateInfo = (row) => {
return http.request({
url: '/api/blade-user/update-info',
method: 'post',
data: row
})
}
// 修改密码
export const updatePassword = (data) => {
return http.request({
url: '/api/blade-user/update-password',
method: 'post',
params: data
})
}
// 修改密码
export const passwordCheck = (data) => {
return http.request({
url: '/api/blade-user/passwordCheck',
method: 'post',
params: data
data
}) })
} }

+ 44
- 9
monitorMobile/common/mixins.vue View File

@@ -58,6 +58,42 @@
return url + query return url + query
}, },
// 获取一个全局变量
// key 为键名
GET_GLOBAL(key) {
return this.$store.state[key]
},
// 设置一个全局变量
// key 为键名
// val 为值
SET_GLOBAL(key, val) {
this.$store.commit(key, val)
},
// 清空全局变量
CLEAR_GLOBAL() {
this.$store.commit('clear')
uni.removeStorageSync('token')
},
// 将数据写入本地缓存
SET_STORAGE(key, data) {
if (data === null) {
uni.removeStorageSync(key)
} else {
uni.setStorageSync(key, data)
}
},
// 获取之前写入本地缓存的数据
GET_STORAGE(key) {
return uni.getStorageSync(key)
},
// 清空本地缓存
CLEAR_STORAGE() {
uni.clearStorageSync()
},
// 设置页面标题 // 设置页面标题
SET_TITLE(title) { SET_TITLE(title) {
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
@@ -103,6 +139,10 @@
}); });
}) })
}, },
// 展示提示框
// title 为提示文字
// mask 为是否禁止点击
// icon 为显示图标,可以改为 'success'
TOAST(title){ TOAST(title){
uni.showToast({ uni.showToast({
icon: "none", icon: "none",
@@ -110,6 +150,10 @@
duration: 2000, duration: 2000,
}); });
}, },
// 停止展示 toast 提示框
HIDE_TOAST() {
uni.hideToast()
},
UPLOAD_FILE(filePath){ UPLOAD_FILE(filePath){
let that = this let that = this
// 假设有token值需要在头部需要携带 // 假设有token值需要在头部需要携带
@@ -179,18 +223,9 @@
data: item, // 要复制的路径 data: item, // 要复制的路径
success: function(res) { success: function(res) {
resolve(true) resolve(true)
// uni.getClipboardData({
// success: function(data) {
// resolve(true)
// },
// fail: function(data1) {
// resolve(false)
// }
// });
} }
}); });
}) })
}, },
}, },
} }

+ 4
- 7
monitorMobile/common/setting.js View File

@@ -3,7 +3,6 @@
*/ */
// #ifdef H5 // #ifdef H5
let origin = window.location.origin let origin = window.location.origin
console.log(window.location.origin)
// #endif // #endif
module.exports = { module.exports = {
// 应用名 // 应用名
@@ -26,8 +25,8 @@ module.exports = {
// 小程序接口Url // 小程序接口Url
// #ifndef H5 // #ifndef H5
// devUrl: 'http://192.168.10.46', // devUrl: 'http://192.168.10.46',
devUrl: 'https://www.bjjyp.org.cn/rider',//开发环境接口Url
prodUrl: `https://www.bjjyp.org.cn/rider`,//线上环境接口Url
devUrl: '',//开发环境接口Url
prodUrl: ``,//线上环境接口Url
// prodUrl: 'http://192.168.100.236:1888', // prodUrl: 'http://192.168.100.236:1888',
// prodUrl: 'http://114.255.136.189:1888', // prodUrl: 'http://114.255.136.189:1888',
// #endif // #endif
@@ -50,8 +49,6 @@ module.exports = {
// token过期时间 // token过期时间
tokenTime: 3000, tokenTime: 3000,
switchMode: true, // 是否开启部门切换模式 switchMode: true, // 是否开启部门切换模式
//本地
previewUrl: 'http://cp.qjkjedu.com/onlinePreview',
//金隅生产
// previewUrl: 'https://www.bjjyp.org.cn/preview/onlinePreview',
//文件预览地址
previewUrl: '',
} }

+ 2
- 22
monitorMobile/http/api.js View File

@@ -12,7 +12,6 @@ import {
import Request from '@/utils/luch-request/index.js'; import Request from '@/utils/luch-request/index.js';
const http = new Request(options); const http = new Request(options);
http.interceptors.request.use((config) => { // 可使用async await 做异步操作 http.interceptors.request.use((config) => { // 可使用async await 做异步操作
// 假设有token值需要在头部需要携带 // 假设有token值需要在头部需要携带
let accessToken = uni.getStorageSync('accessToken'); let accessToken = uni.getStorageSync('accessToken');
if (accessToken) { if (accessToken) {
@@ -24,29 +23,10 @@ http.interceptors.request.use((config) => { // 可使用async await 做异步操
// #ifndef H5 // #ifndef H5
let url = config.url let url = config.url
if (process.env.NODE_ENV == 'development' && !url.startsWith("http")) { if (process.env.NODE_ENV == 'development' && !url.startsWith("http")) {
// url = url.substring(url.indexOf('/api') + 4)
config.url = url config.url = url
} }
// #endif // #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 return config
}, config => { // 可使用async await 做异步操作 }, config => { // 可使用async await 做异步操作
return Promise.reject(config) return Promise.reject(config)
@@ -80,7 +60,7 @@ http.interceptors.response.use((response) => {
const pages = getCurrentPages() const pages = getCurrentPages()
const currentPage = pages[pages.length - 1] const currentPage = pages[pages.length - 1]
uni.redirectTo({ uni.redirectTo({
url: `/pages/login/login?redirect=/${currentPage.route}`
url: `pages/login?redirect=/${currentPage.route}`
}) })
} }
return Promise.reject(response) return Promise.reject(response)


+ 1
- 1
monitorMobile/http/config.js View File

@@ -44,6 +44,6 @@ var options = {
// previewUrl: 'https://www.bjjyp.org.cn/preview/onlinePreview', // previewUrl: 'https://www.bjjyp.org.cn/preview/onlinePreview',
// previewUrl: 'http://114.255.136.189:6696/onlinePreview', // previewUrl: 'http://114.255.136.189:6696/onlinePreview',
// previewUrl: 'http://192.168.100.236:85/onlinePreview', // previewUrl: 'http://192.168.100.236:85/onlinePreview',
previewUrl: 'http://cp.qjkjedu.com/onlinePreview',
previewUrl: '',
}; };
export { options }; export { options };

+ 1
- 3
monitorMobile/main.js View File

@@ -1,12 +1,9 @@
import App from './App' import App from './App'
import Vue from 'vue' import Vue from 'vue'
import store from '@/store';
import mixins from '@/common/mixins.vue' import mixins from '@/common/mixins.vue'

Vue.mixin(mixins) Vue.mixin(mixins)


// 引入vuex // 引入vuex
Vue.prototype.$u = {}
const vuexStore = require("@/store/$u.mixin.js"); const vuexStore = require("@/store/$u.mixin.js");
Vue.mixin(vuexStore); Vue.mixin(vuexStore);


@@ -34,6 +31,7 @@ export function createApp() {
} }
// #endif // #endif


// 添加http实例
import http from '@/http/api.js' import http from '@/http/api.js'
Vue.prototype.$http = http Vue.prototype.$http = http




+ 21
- 8
monitorMobile/pages/login.vue View File

@@ -37,7 +37,9 @@
</template> </template>


<script> <script>
import {token} from '@/api/user.js'
import {
login
} from '@/api/user.js'
export default { export default {
data() { data() {
return { return {
@@ -47,13 +49,14 @@
}, },
passType: 'password', passType: 'password',
isLoading: false, isLoading: false,
redirect:'',
rules: { rules: {
account: [{ account: [{
required: true, required: true,
message: '请输入账号', message: '请输入账号',
trigger: ['blur', 'change'] trigger: ['blur', 'change']
}], }],
pass: [{
password: [{
required: true, required: true,
message: '请输入密码', message: '请输入密码',
trigger: ['blur', 'change'] trigger: ['blur', 'change']
@@ -69,12 +72,22 @@
} }
} }
}, },
onLoad(e) {
if (e.redirect) this.redirect = redirect
// this.username = ''
// this.password = ''
},
methods: { methods: {
login() { login() {
token()
this.$refs.uForm.validate(valid => {
if (!valid) return
this.$refs.uForm.validate().then(() => {
this.isLoading = true this.isLoading = true
login(this.form).then(res => {
this.isLoading = false
console.log(res)
}).catch(()=>{
this.isLoading = false
})
}) })
} }
}, },
@@ -99,7 +112,7 @@
} }


input[type="password"]::-ms-reveal { input[type="password"]::-ms-reveal {
display: none!important;
display: none !important;
} }


.logoBox { .logoBox {
@@ -138,8 +151,8 @@
margin-bottom: 30rpx; margin-bottom: 30rpx;
// font-weight: 700; // font-weight: 700;
} }
/deep/.u-form-item__body{
/deep/.u-form-item__body {
padding: 15rpx 0; padding: 15rpx 0;
} }
} }

+ 0
- 1
monitorMobile/store/$u.mixin.js View File

@@ -15,7 +15,6 @@ module.exports = {
mounted() { mounted() {
// 将vuex方法挂在到$u中 // 将vuex方法挂在到$u中
// 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex('user.name', '史诗') // 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex('user.name', '史诗')
// 如果要修改vuex的state的version变量为1.0.1 => this.$u.vue x('version', '1.0.1')
this.$u.vuex = (name, value) => { this.$u.vuex = (name, value) => {
this.$store.commit('$uStore', { this.$store.commit('$uStore', {
name, name,


+ 8
- 8
monitorMobile/store/index.js View File

@@ -38,13 +38,13 @@ const store = new Vuex.Store({
// 下面这些值仅为示例,使用过程中请删除 // 下面这些值仅为示例,使用过程中请删除
state: { state: {
// 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量 // 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
userInfo: lifeData.userInfo ? lifeData.userInfo : {
avatar: '',
nick_name: '游客',
tenant_id: '暂无'
},
accessToken: lifeData.accessToken ? lifeData.accessToken : '',
isLogin: lifeData.isLogin ? lifeData.isLogin : false,
// userInfo: lifeData.userInfo ? lifeData.userInfo : {
// avatar: '',
// nick_name: '游客',
// tenant_id: '暂无'
// },
// accessToken: lifeData.accessToken ? lifeData.accessToken : '',
// isLogin: lifeData.isLogin ? lifeData.isLogin : false,
}, },
mutations: { mutations: {
$uStore(state, payload) { $uStore(state, payload) {
@@ -69,5 +69,5 @@ const store = new Vuex.Store({
} }
} }
}) })
Vue.prototype.$store = store
export default store export default store

Loading…
Cancel
Save