App.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <script>
  2. import { onMounted, ref } from 'vue'
  3. import * as link from '@/lib/link'
  4. import rest from '@/stores/rest'
  5. import dd from 'gdt-jsapi';
  6. import { useUserStore } from '@/lib/store'
  7. import { storeToRefs } from 'pinia'
  8. export default {
  9. setup() {
  10. const store = useUserStore();
  11. const { globalParameter } = storeToRefs(store);
  12. const formData = ref({
  13. appkey: null,
  14. appsecret: null,
  15. authCode: null,
  16. domainname: null,
  17. })
  18. const getBasicInfo = ()=> {
  19. console.log("监听咯")
  20. getAuthCode()
  21. }
  22. const getAuthCode = () => {
  23. console.log("监听咯-getAuthCode")
  24. dd.ready(()=> {
  25. dd.getAuthCode({}).then((result) => {
  26. if (result.code){
  27. formData.value.authCode = result.code
  28. }else {
  29. formData.value.authCode = result.auth_code
  30. }
  31. globalParameter.value.authCode = formData.value.authCode
  32. localStorage.setItem('authCode', formData.value.authCode);
  33. }).catch(err => {
  34. link.goLogin()
  35. })
  36. })
  37. }
  38. const getUserInfo = async () => {
  39. try {
  40. await rest.post('/zyyp/ykz/getUserInfo?authCode='+ formData.value.authCode,'')
  41. } catch (error) {
  42. console.error(error);
  43. }
  44. };
  45. const startIntervalTask = () => {
  46. // 每 60 分钟执行一次任务
  47. setInterval(() => {
  48. getBasicInfo();
  49. }, 60 * 60 * 1000); // 60 分钟
  50. };
  51. onMounted(() => {
  52. console.log('App Created');
  53. startIntervalTask();
  54. });
  55. return {
  56. formData,
  57. getBasicInfo,
  58. getAuthCode,
  59. getUserInfo,
  60. startIntervalTask,
  61. };
  62. }
  63. }
  64. </script>
  65. <style lang="scss">
  66. /*每个页面公共css */
  67. @import "uni.scss";
  68. @import "static/style/base.scss";
  69. </style>