App.vue 1.5 KB

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