Commit cf970f11 authored by peco's avatar peco

feat:授权 和 admin 相关处理

parent 6f19e4e6
...@@ -17,6 +17,12 @@ const install = (Vue, vm) => { ...@@ -17,6 +17,12 @@ const install = (Vue, vm) => {
const getUserListCount = params => vm.$u.get(`${baseUrl}/report/user/getUserListCount`, params) const getUserListCount = params => vm.$u.get(`${baseUrl}/report/user/getUserListCount`, params)
// 修改密码 // 修改密码
const changePassword = params => vm.$u.post(`${baseUrl}/report/user/changePassword`, params) const changePassword = params => vm.$u.post(`${baseUrl}/report/user/changePassword`, params)
// 获取用户数据
const getAuthorizedList = params => vm.$u.get(`${baseUrl}/report/user/getAuthorizedList`, params)
// 授权/取消授权
const authorizeOrUnauthorize = params => vm.$u.post(`${baseUrl}/report/user/authorizeOrUnauthorize`, params)
// 获取OPENID
const getOpenId = params => vm.$u.get(`${baseUrl}/report/user/getOpenId`, params)
vm.$u.api = { vm.$u.api = {
quickLogin, quickLogin,
...@@ -25,7 +31,10 @@ const install = (Vue, vm) => { ...@@ -25,7 +31,10 @@ const install = (Vue, vm) => {
dataSetPreview, dataSetPreview,
getAuthorized, getAuthorized,
getUserListCount, getUserListCount,
changePassword changePassword,
getAuthorizedList,
authorizeOrUnauthorize,
getOpenId
} }
} }
......
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
</view> </view>
</block> </block>
</view> </view>
<view class="subscribe" v-if="admin" @tap='subscribe()'>
订阅消息
</view>
<u-button <u-button
class="my-u-block u-m-t-80" class="my-u-block u-m-t-80"
type="warning" type="warning"
...@@ -47,7 +52,7 @@ ...@@ -47,7 +52,7 @@
{ 'text': '待授权', 'show': true, 'count': '0' }, { 'text': '待授权', 'show': true, 'count': '0' },
{ 'text': '已授权', 'show': true, 'count': '0'}]; { 'text': '已授权', 'show': true, 'count': '0'}];
this.$u.api.getUserListCount({param}).then(res=>{ this.$u.api.getUserListCount(param).then(res=>{
const { Status, Result } = res.data const { Status, Result } = res.data
if (Status === 'true') { if (Status === 'true') {
itemList[1].count = Result.no_authorized; itemList[1].count = Result.no_authorized;
...@@ -85,6 +90,32 @@ ...@@ -85,6 +90,32 @@
break; break;
} }
}, },
// 订阅消息
subscribe() {
var that = this
uni.login({
provider: 'weixin',
success: function(res) {
var code = res.code
var param = {
code: code,
id: uni.getStorageSync('userId')
}
that.$u.api.getOpenId(param).then(res=>{
const { Status, Result } = res.data
if (Status === 'true') {
}
})
}
})
uni.requestSubscribeMessage({
tmplIds: ['GSPZ_GSbsgfRSu8wugGPe2zqmReDbY8yeIEqd8pPPM8'],
success (res) {
console.log('授权结果' + res['GSPZ_GSbsgfRSu8wugGPe2zqmReDbY8yeIEqd8pPPM8'])
}
})
},
// 退出登录 // 退出登录
logout() { logout() {
uni.removeStorageSync('userId'); uni.removeStorageSync('userId');
...@@ -121,10 +152,22 @@ ...@@ -121,10 +152,22 @@
} }
.item-cell-text { .item-cell-text {
margin-left: 20rpx; margin-left: 20rpx;
font-size: 24rpx; font-size: 28rpx;
} }
.item-cell-list-count { .item-cell-list-count {
margin-left: 300rpx; margin-left: 300rpx;
font-size: 24rpx; font-size: 28rpx;
}
.subscribe {
width: 30%;
text-align: center;
font-size: 30rpx;
border: 0.1rpx solid #cccccc;
border-radius: 10rpx;
margin: 60rpx;
padding: 25rpx 0rpx 25rpx 0rpx;
display: flex;
justify-content: center;
margin-left: 35%;
} }
</style> </style>
\ No newline at end of file
<template> <template>
<view> <view class="wrap">
授权列表 <view class="item-list">
<block v-for="(item,index) in userList">
<view class="item-cell">
<view class="item-name">{{item.userName}}</view>
<view class="item-button" @tap ="authorized(item.id, item.authorized, index)" v-if="item.authorized">取消授权</view>
<view class="item-button" @tap ="authorized(item.id, item.authorized, index)" v-else>授权</view>
</view>
</block>
</view>
</view> </view>
</template> </template>
...@@ -8,15 +16,107 @@ ...@@ -8,15 +16,107 @@
export default { export default {
data() { data() {
return { return {
confirmed: '',
userList: []
} }
}, },
onLoad(option) {
var copfirmed = option.confirmed
this.$data.confirmed = copfirmed
},
onShow() {
this.judgeAndLoad()
},
methods: { methods: {
// 判断权限和加载数据
judgeAndLoad() {
var isAdmin = uni.getStorageSync('admin')
if (isAdmin) {
this.getUserList()
} else {
this.$u.toast('您没有操作权限')
uni.navigateBack({
})
}
if (this.$data.confirmed === 'true') {
uni.setNavigationBarTitle({
title: '已授权列表'
})
} else {
uni.setNavigationBarTitle({
title: '待授权列表'
})
}
},
// 获取列表
getUserList() {
var userId = uni.getStorageSync('userId')
var param = {
id: userId,
authorized: this.$data.confirmed
}
this.$u.api.getAuthorizedList(param).then(res=>{
const { Status, Result } = res.data
if (Status === 'true' || Result.length > 0) {
this.$data.userList = Result
} else {
this.$data.userList = []
}
})
},
// 授权
authorized(id, authorized, index) {
var type = authorized ? 'unthorize' : 'authorize'
var operatorId = uni.getStorageSync('userId')
var param = {
type: type,
id: id,
operatorId: operatorId
}
this.$u.api.authorizeOrUnauthorize(param).then(res=>{
const { Status, Result } = res.data
if (Status === 'true') {
this.$data.userList.splice(index,1)
this.$u.toast('操作成功')
} else {
this.$u.toast('操作失败')
}
})
}
},
// 下拉刷新
onPullDownRefresh() {
this.judgeAndLoad()
uni.stopPullDownRefresh()
} }
} }
</script> </script>
<style> <style lang="scss" scoped>
.item-list {
display: flex;
flex-direction: column;
}
.item-cell {
display: flex;
position: relative;
justify-content: space-between;
width: 100%;
height: 100rpx;
align-items: center;
border-bottom: 0.1rpx solid #cccccc;
}
.item-name {
margin-left: 20rpx;
font-size: 28rpx;
}
.item-button {
margin-right: 40rpx;
font-size: 28rpx;
border: 0.1rpx solid #cccccc;
border-radius: 5rpx;
padding: 10rpx 20rpx 10rpx 20rpx;
}
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment