index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import stringify from '@/utils/querystring'
  2. import { isWeixin } from '@/utils/util'
  3. import router from './router'
  4. import cookie from './cookie'
  5. import { useMainStore } from '@/store/store'
  6. export const handleLoginFailure = () => {
  7. uni.removeStorageSync('userinfo');
  8. uni.removeStorageSync('accessToken');
  9. const main = useMainStore()
  10. main.SET_MEMBER({});
  11. main.SET_TOKEN('');
  12. // #ifdef H5
  13. if(isWeixin()){
  14. uni.switchTab({
  15. url: '/pages/index/index'
  16. })
  17. return
  18. }
  19. // #endif
  20. uni.redirectTo({
  21. url: '/pages/components/pages/login/login',
  22. })
  23. }
  24. export function parseUrl(location) {
  25. if (typeof location === 'string') return location
  26. const { url, query } = location
  27. const queryStr = stringify(query)
  28. if (!queryStr) {
  29. return url
  30. }
  31. return `${url}?${queryStr}`
  32. }
  33. const toAuth = () => {
  34. uni.showToast({
  35. title: '暂未开放',
  36. icon: 'none',
  37. duration: 2000,
  38. })
  39. }
  40. export default {
  41. install: (app, options) => {
  42. // 在这里编写插件代码
  43. // 注入一个全局可用的 $translate() 方法
  44. app.config.globalProperties.$yrouter = router
  45. app.config.globalProperties.$cookie = cookie
  46. app.config.globalProperties.$toAuth = toAuth
  47. app.config.globalProperties.$onClickLeft = () => {
  48. router.back()
  49. //uni.navigateBack()
  50. //const mypage = getCurrentPages()
  51. //console.log('mypage:',mypage)
  52. }
  53. // #ifdef H5
  54. app.config.globalProperties.$platform = 'h5'
  55. // #endif
  56. // #ifdef APP-PLUS
  57. // app端
  58. app.config.globalProperties.$platform = 'app'
  59. // #endif
  60. // #ifdef MP-WEIXIN
  61. app.config.globalProperties.$platform = 'routine'
  62. // #endif
  63. },
  64. }