123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- <!--
- * @Author: yangpeiqin
- * @Date: 2023-12-11 10:13:55
- * @LastEditors: yangpeiqin
- * @LastEditTime: 2023-12-15 15:35:36
- * @FilePath: \gdtq_admin_app移动端\App.vue
- -->
- <script>
- import { getToken } from '@/utils/auth'
- import * as dd from 'dingtalk-jsapi'; // 此方式为整体加载,也可按需进行加载
- import Vue from 'vue'
- import {getThirdH5Auth,h5GetToken} from '@/api/login.js'
- export default {
- onLaunch: function ({query}) {
- console.log('App Launch')
- this.$store.dispatch('appConfig/ConfigList');
-
- if(Vue.prototype.hasHostPlat(["dingH5"]) && Vue.prototype.hasPlat(["enterprises"])) {
- this.handleDingLogin(query)
- } else if(Vue.prototype.hasHostPlat(["dingH5Ins"]) && Vue.prototype.hasPlat(["enterprises"])) {
- this.handleDingInsLogin(query)
- } else {
- this.otherLogin(query)
- }
- },
- onShow: function () {
- console.log('App Show')
- // this.checkTabPer()
-
- },
- onHide: function () {
- console.log('App Hide')
- },
- methods: {
- checkTabPer() {
- if(Vue.prototype.hasPlat(["enterprises"])) {
-
- if(Vue.prototype.$hasPermi('mobile:index:base:driverTask')) {
- // 司机任务tab
- uni.setTabBarItem({
- index:1, //从左到右 0开始
- visible:true ,//默认true false隐藏
- })
- } else {
- // 司机任务tab
- uni.setTabBarItem({
- index:1, //从左到右 0开始
- visible:false ,//默认true false隐藏
- })
- }
- } else {
- // 司机任务tab
- uni.setTabBarItem({
- index:1, //从左到右 0开始
- visible:false ,//默认true false隐藏
- })
- }
-
- },
- otherLogin(query) {
- if (query.token) {
- this.$store.dispatch('setTokenData', {
- token: query.token
- }).then(() => {
- this.getUserInfo()
- })
- return
- }
-
- if (getToken()) {
- this.getUserInfo()
- }
- },
- //钉钉第三方应用登录
- handleDingLogin(query={}) {
-
- if(dd.env.platform == "notInDingTalk") return
-
- if (query.token) {
- this.$store.dispatch('setTokenData', {
- token: query.token
- }).then(() => {
- this.getUserInfo()
- })
- return
- }
-
- if(query && query.corpId) {
- uni.setStorageSync("corpId", query.corpId);
- this.dingLogin(query.corpId)
-
- return
- } else if (getToken()) {
- this.getUserInfo()
- }
-
- },
- //钉钉内部应用登录
- handleDingInsLogin(query={}) {
-
- if(dd.env.platform == "notInDingTalk") return
-
- if (query.token) {
- this.$store.dispatch('setTokenData', {
- token: query.token
- }).then(() => {
- this.getUserInfo()
- })
- return
- }
-
- if(query && query.corpId) {
- uni.setStorageSync("corpId", query.corpId);
- this.dingInsLogin(query.corpId)
-
- return
- } else if (getToken()) {
- this.getUserInfo()
- }
-
- },
- getUserInfo() {
-
- this.$store.dispatch('GetInfo').then(res => {
-
- const {path} = this.$route
- if(path =='/') {
- uni.switchTab({
- url: '/pages/index/index'
- });
- }
- this.checkTabPer()
-
- })
- },
- // 第三方应用获取token
- dingLogin(corpId) {
- dd.getAuthCode({
- corpId: corpId,
- // corpId: 'ding7ea3eb9200c0101c35c2f4657eb6378f',
- success: (res) => {
-
- const { code } = res;
-
- if(code) {
-
- getThirdH5Auth({code,corpId}).then((res) => {
-
- this.$store.state.user.isModel = false
- this.$store.state.user.cacheToken = null
-
- this.$store.dispatch('setTokenData', {
- token: res.data
- }).then(() => {
- this.getUserInfo()
- })
- }).catch((err) => {
-
- uni.showModal({
- title: '提示',
- content: `${err}`,
- showCancel:false,
- confirmText: '确定',
- success: function(res) {
- if (res.confirm) {
-
- }
- }
- })
-
- })
- }
- },
- fail: (res) => {
- uni.showModal({
- title: '提示',
- content: `${res.errorMessage}`,
- showCancel:false,
- confirmText: '确定',
- success: function(res) {
- if (res.confirm) {
-
- }
- }
- })
- },
- complete: () => {},
- });
- },
- // 内部应用获取token
- dingInsLogin(corpId) {
- dd.getAuthCode({
- corpId: corpId,
- // corpId: 'ding7ea3eb9200c0101c35c2f4657eb6378f',
- success: (res) => {
-
- const { code } = res;
-
- if(code) {
-
- h5GetToken({code,corpId}).then((res) => {
-
- this.$store.state.user.isModel = false
- this.$store.state.user.cacheToken = null
-
- this.$store.dispatch('setTokenData', {
- token: res.data
- }).then(() => {
- this.getUserInfo()
- })
- }).catch((err) => {
-
- uni.showModal({
- title: '提示',
- content: `${err}`,
- showCancel:false,
- confirmText: '确定',
- success: function(res) {
- if (res.confirm) {
-
- }
- }
- })
-
- })
- }
- },
- fail: (res) => {
- uni.showModal({
- title: '提示',
- content: `${res.errorMessage}`,
- showCancel:false,
- confirmText: '确定',
- success: function(res) {
- if (res.confirm) {
-
- }
- }
- })
- },
- complete: () => {},
- });
- },
-
-
- //下载
- doUpData(appUrl) {
- uni.showLoading({
- title: '更新中……'
- })
- uni.downloadFile({//执行下载
- url: appUrl, //下载地址
- success: downloadResult => {//下载成功
- uni.hideLoading();
- if (downloadResult.statusCode == 200) {
- uni.showModal({
- title: '',
- content: '更新成功,确定现在重启吗?',
- confirmText: '重启',
- confirmColor: '#EE8F57',
- success: function (res) {
- if (res.confirm == true) {
- plus.runtime.install(//安装
- downloadResult.tempFilePath, {
- force: true
- },
- function (res) {
- utils.showToast('更新成功,重启中');
- plus.runtime.restart();
- }
- );
- }
- }
- });
- }
- }
- });
- },
- }
- }
- </script>
- <style lang="scss">
- @import '@/common/css/icon.css';
- @import "uview-ui/index.scss";
- @import "@/assets/styles/uview-ui.scss";
- // 默认背景颜色
- page {
- background: #f3f4f8;
- width: 100%;
- height: 100%;
- }
- view {
- width: auto;
- word-wrap: break-word;
- white-space: normal;
- word-break: break-all;
- }
- .u-cell {
- width: 100%;
- }
- /*每个页面公共css */
- </style>
|