| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <template>
- <view>
- <view v-if="showLogin">
- <login :ocode="ocode" :appkey="appkey" scope="snsapi_userinfo" :visible="visible" @success="loginSuccess" @fail="loginFail" @cancel="loginCancel" />
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- // 获取用户信息
- ocode: '1015730314',
- // 商户appkey
- appkey: 'EE28EE2C93296F4E',
- // 是否授权可见
- visible: false,
- // 是否启动授权
- showLogin: false,
- // 获取用户信息
- appid: 'wxd6f090391d410534',
- // repairsUserInfo: {
- // routes: ['首页', '工单管理', '待处理池']
- // },
- // 用户路由
- userListInfo: {
- routes: ['报修', '我的报修'],
- btns: []
- },
- // 师傅路由
- workerListInfo: {
- routes: ['首页', '工单管理', '待处理池'],
- btns: ['协作', '接单', '转单', '报价', '维修完成']
- },
- // 后勤路由
- logisticsListInfo: {
- routes: ['首页', '工单管理', '待处理池', '通讯录'],
- btns: ['表格编辑', '延时', '派单', '审核', '分段器按钮']
- },
- // 管理者路由
- adminListInfo: {
- routes: ['首页', '工单管理', '待处理池', '通讯录'],
- btns: ['首页分段器', '表格编辑', '工单管理分段器', '延时', '派单', '审核', '接单', '报价', '维修完成']
- }
- }
- },
- mounted() {
- // this.hasUserInfo()
- uni.setStorageSync('currentIndexRepairs', 0)
- uni.showActionSheet({
- itemList: ['用户', '维修师傅', '管理员', '后勤'],
- success: (res) => {
- if (res.tapIndex == 0) {
- uni.setStorageSync('repairsUserInfo', this.userListInfo)
- } else if (res.tapIndex == 1) {
- uni.setStorageSync('repairsUserInfo', this.workerListInfo)
- } else if (res.tapIndex == 2) {
- uni.setStorageSync('repairsUserInfo', this.adminListInfo)
- } else if (res.tapIndex == 3) {
- uni.setStorageSync('repairsUserInfo', this.logisticsListInfo)
- }
- uni.reLaunch({
- url: '/pagesRepairs/box/box'
- })
- }
- })
- },
- methods: {
- // 检查是否存在用户信息
- hasUserInfo() {
- const repairsUserInfo = uni.getStorageSync('repairsUserInfo')
- console.log(repairsUserInfo)
- if (repairsUserInfo) {
- uni.reLaunch({
- url: '/pagesRepairs/box/box'
- })
- } else {
- console.log('重新授权')
- // uni.setStorageSync('repairsUserInfo', this.userListInfo)
- // uni.reLaunch({
- // url: '/pagesRepairs/box/box'
- // })
- this.showLogin = true
- this.visible = true
- }
- },
- // 授权成功回调
- loginSuccess(res) {
- console.log('成功')
- let wxcode = res.detail.wxcode
- console.log(wxcode)
- // 获取wxcode后请求登录
- this.login(wxcode)
- },
- // 授权失败回调
- loginFail() {
- // console.log("授权失败");
- uni.showModal({
- title: '提示',
- content: '授权:请先领取校园卡、并激活!',
- confirmText: '领取',
- success: (res) => {
- if (res.confirm) {
- uni.reLaunch({
- url: '/pages/qr_code/qr_code'
- })
- } else if (res.cancel) {
- uni.reLaunch({
- url: '/pagesClockIn/404/404'
- })
- }
- }
- })
- },
- // 授权取消回调
- loginCancel() {
- // console.log("取消");
- uni.showModal({
- title: '提示',
- content: '请先授权,否则无法使用该功能',
- confirmText: '授权',
- success: (res) => {
- if (res.confirm) {
- uni.reLaunch({
- url: '/pagesRepairs/index/index'
- })
- } else if (res.cancel) {
- uni.reLaunch({
- url: '/pagesClockIn/404/404'
- })
- }
- }
- })
- },
- // 用户登陆获取个人信息和token
- async login(wxcode) {
- const res = await this.$myRequest_repairs({
- url: '/repair/api/login/Openid',
- // header: {
- // 'content-type': 'application/json',
- // platform: 2,
- // 'Accept-Language': 'zh-CN,zh;q=0.9'
- // },
- data: {
- // redirect_uri: `mnp://${this.appid}`,
- wxcode
- }
- })
- console.log(res)
- // if (res.code == 200) {
- // uni.setStorageSync('token', res.data.token)
- // uni.reLaunch({
- // url: '/pagesRepairs/box/box'
- // })
- // } else {
- // uni.showToast({
- // title: res.message,
- // icon: 'none'
- // })
- // }
- }
- }
- }
- </script>
- <style lang="scss"></style>
|