App.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <!--
  2. * @Author: yangpeiqin
  3. * @Date: 2023-12-11 10:13:55
  4. * @LastEditors: yangpeiqin
  5. * @LastEditTime: 2023-12-15 15:35:36
  6. * @FilePath: \gdtq_admin_app移动端\App.vue
  7. -->
  8. <script>
  9. import { getToken } from '@/utils/auth'
  10. import * as dd from 'dingtalk-jsapi'; // 此方式为整体加载,也可按需进行加载
  11. import Vue from 'vue'
  12. import {getThirdH5Auth,h5GetToken} from '@/api/login.js'
  13. export default {
  14. onLaunch: function ({query}) {
  15. console.log('App Launch')
  16. this.$store.dispatch('appConfig/ConfigList');
  17. if(Vue.prototype.hasHostPlat(["dingH5"]) && Vue.prototype.hasPlat(["enterprises"])) {
  18. this.handleDingLogin(query)
  19. } else if(Vue.prototype.hasHostPlat(["dingH5Ins"]) && Vue.prototype.hasPlat(["enterprises"])) {
  20. this.handleDingInsLogin(query)
  21. } else {
  22. this.otherLogin(query)
  23. }
  24. },
  25. onShow: function () {
  26. console.log('App Show')
  27. // this.checkTabPer()
  28. },
  29. onHide: function () {
  30. console.log('App Hide')
  31. },
  32. methods: {
  33. checkTabPer() {
  34. if(Vue.prototype.hasPlat(["enterprises"])) {
  35. if(Vue.prototype.$hasPermi('mobile:index:base:driverTask')) {
  36. // 司机任务tab
  37. uni.setTabBarItem({
  38. index:1, //从左到右 0开始
  39. visible:true ,//默认true false隐藏
  40. })
  41. } else {
  42. // 司机任务tab
  43. uni.setTabBarItem({
  44. index:1, //从左到右 0开始
  45. visible:false ,//默认true false隐藏
  46. })
  47. }
  48. } else {
  49. // 司机任务tab
  50. uni.setTabBarItem({
  51. index:1, //从左到右 0开始
  52. visible:false ,//默认true false隐藏
  53. })
  54. }
  55. },
  56. otherLogin(query) {
  57. if (query.token) {
  58. this.$store.dispatch('setTokenData', {
  59. token: query.token
  60. }).then(() => {
  61. this.getUserInfo()
  62. })
  63. return
  64. }
  65. if (getToken()) {
  66. this.getUserInfo()
  67. }
  68. },
  69. //钉钉第三方应用登录
  70. handleDingLogin(query={}) {
  71. if(dd.env.platform == "notInDingTalk") return
  72. if (query.token) {
  73. this.$store.dispatch('setTokenData', {
  74. token: query.token
  75. }).then(() => {
  76. this.getUserInfo()
  77. })
  78. return
  79. }
  80. if(query && query.corpId) {
  81. uni.setStorageSync("corpId", query.corpId);
  82. this.dingLogin(query.corpId)
  83. return
  84. } else if (getToken()) {
  85. this.getUserInfo()
  86. }
  87. },
  88. //钉钉内部应用登录
  89. handleDingInsLogin(query={}) {
  90. if(dd.env.platform == "notInDingTalk") return
  91. if (query.token) {
  92. this.$store.dispatch('setTokenData', {
  93. token: query.token
  94. }).then(() => {
  95. this.getUserInfo()
  96. })
  97. return
  98. }
  99. if(query && query.corpId) {
  100. uni.setStorageSync("corpId", query.corpId);
  101. this.dingInsLogin(query.corpId)
  102. return
  103. } else if (getToken()) {
  104. this.getUserInfo()
  105. }
  106. },
  107. getUserInfo() {
  108. this.$store.dispatch('GetInfo').then(res => {
  109. const {path} = this.$route
  110. if(path =='/') {
  111. uni.switchTab({
  112. url: '/pages/index/index'
  113. });
  114. }
  115. this.checkTabPer()
  116. })
  117. },
  118. // 第三方应用获取token
  119. dingLogin(corpId) {
  120. dd.getAuthCode({
  121. corpId: corpId,
  122. // corpId: 'ding7ea3eb9200c0101c35c2f4657eb6378f',
  123. success: (res) => {
  124. const { code } = res;
  125. if(code) {
  126. getThirdH5Auth({code,corpId}).then((res) => {
  127. this.$store.state.user.isModel = false
  128. this.$store.state.user.cacheToken = null
  129. this.$store.dispatch('setTokenData', {
  130. token: res.data
  131. }).then(() => {
  132. this.getUserInfo()
  133. })
  134. }).catch((err) => {
  135. uni.showModal({
  136. title: '提示',
  137. content: `${err}`,
  138. showCancel:false,
  139. confirmText: '确定',
  140. success: function(res) {
  141. if (res.confirm) {
  142. }
  143. }
  144. })
  145. })
  146. }
  147. },
  148. fail: (res) => {
  149. uni.showModal({
  150. title: '提示',
  151. content: `${res.errorMessage}`,
  152. showCancel:false,
  153. confirmText: '确定',
  154. success: function(res) {
  155. if (res.confirm) {
  156. }
  157. }
  158. })
  159. },
  160. complete: () => {},
  161. });
  162. },
  163. // 内部应用获取token
  164. dingInsLogin(corpId) {
  165. dd.getAuthCode({
  166. corpId: corpId,
  167. // corpId: 'ding7ea3eb9200c0101c35c2f4657eb6378f',
  168. success: (res) => {
  169. const { code } = res;
  170. if(code) {
  171. h5GetToken({code,corpId}).then((res) => {
  172. this.$store.state.user.isModel = false
  173. this.$store.state.user.cacheToken = null
  174. this.$store.dispatch('setTokenData', {
  175. token: res.data
  176. }).then(() => {
  177. this.getUserInfo()
  178. })
  179. }).catch((err) => {
  180. uni.showModal({
  181. title: '提示',
  182. content: `${err}`,
  183. showCancel:false,
  184. confirmText: '确定',
  185. success: function(res) {
  186. if (res.confirm) {
  187. }
  188. }
  189. })
  190. })
  191. }
  192. },
  193. fail: (res) => {
  194. uni.showModal({
  195. title: '提示',
  196. content: `${res.errorMessage}`,
  197. showCancel:false,
  198. confirmText: '确定',
  199. success: function(res) {
  200. if (res.confirm) {
  201. }
  202. }
  203. })
  204. },
  205. complete: () => {},
  206. });
  207. },
  208. //下载
  209. doUpData(appUrl) {
  210. uni.showLoading({
  211. title: '更新中……'
  212. })
  213. uni.downloadFile({//执行下载
  214. url: appUrl, //下载地址
  215. success: downloadResult => {//下载成功
  216. uni.hideLoading();
  217. if (downloadResult.statusCode == 200) {
  218. uni.showModal({
  219. title: '',
  220. content: '更新成功,确定现在重启吗?',
  221. confirmText: '重启',
  222. confirmColor: '#EE8F57',
  223. success: function (res) {
  224. if (res.confirm == true) {
  225. plus.runtime.install(//安装
  226. downloadResult.tempFilePath, {
  227. force: true
  228. },
  229. function (res) {
  230. utils.showToast('更新成功,重启中');
  231. plus.runtime.restart();
  232. }
  233. );
  234. }
  235. }
  236. });
  237. }
  238. }
  239. });
  240. },
  241. }
  242. }
  243. </script>
  244. <style lang="scss">
  245. @import '@/common/css/icon.css';
  246. @import "uview-ui/index.scss";
  247. @import "@/assets/styles/uview-ui.scss";
  248. // 默认背景颜色
  249. page {
  250. background: #f3f4f8;
  251. width: 100%;
  252. height: 100%;
  253. }
  254. view {
  255. width: auto;
  256. word-wrap: break-word;
  257. white-space: normal;
  258. word-break: break-all;
  259. }
  260. .u-cell {
  261. width: 100%;
  262. }
  263. /*每个页面公共css */
  264. </style>