App.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. }).catch(err => {
  33. link.goLogin()
  34. })
  35. })
  36. }
  37. const getUserInfo = async () => {
  38. try {
  39. await rest.post('/zyyp/ykz/getUserInfo?authCode='+ formData.value.authCode,'')
  40. } catch (error) {
  41. console.error(error);
  42. }
  43. };
  44. const startIntervalTask = () => {
  45. // 每 60 分钟执行一次任务
  46. setInterval(() => {
  47. getBasicInfo();
  48. }, 60 * 60 * 1000); // 60 分钟
  49. };
  50. onMounted(() => {
  51. console.log('App Created');
  52. startIntervalTask();
  53. });
  54. return {
  55. formData,
  56. getBasicInfo,
  57. getAuthCode,
  58. getUserInfo,
  59. startIntervalTask,
  60. };
  61. }
  62. }
  63. </script>
  64. <style lang="scss">
  65. /*每个页面公共css */
  66. @import "uni.scss";
  67. @import "static/style/base.scss";
  68. </style>