app.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { showToast } from './utils/feedback'
  2. import { formatTime, arrRemoveObj,getTypeItem } from './utils/util'
  3. const baseUrl = "https://test-ding.g107.com/";//测试
  4. // const baseUrl = "https://ding.insys.g107.com/";//正式
  5. var that;
  6. App({
  7. //自定义全局变量
  8. globalData: {
  9. showToast: showToast,//提示框
  10. arrRemoveObj: arrRemoveObj,//删除数组的某一项
  11. year: formatTime(new Date()).year,//当前年
  12. month: formatTime(new Date()).month,//当前月
  13. day: formatTime(new Date()).day,//当前日
  14. types:[],
  15. userData: '',
  16. token:'',
  17. // token:' eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC90ZXN0LWRpbmcuZzEwNy5jb21cL2FwaVwvdGVzdCIsImlhdCI6MTU5Nzg4NjUyOSwiZXhwIjoxNTk4NDg2NTI5LCJuYmYiOjE1OTc4ODY1MjksImp0aSI6IktvRmR2bk1VVThaN2poWjkiLCJzdWIiOjEsInBydiI6ImNhNjQ4OWQ1MGYyNDA3YTY3ODMwZTgwOTBkMDE0ODgzNTY4NTk2MmIiLCJyb2xlIjoiZW1wbG95ZWUifQ.1gjqd9WgrK7N_ugz0ljIniScr8fCBucFzNJE3Cjo1sg',
  18. ALIOSS_URL: 'https://integralsys.oss-cn-shenzhen.aliyuncs.com',
  19. imgHttpUrl:'https://intesys.cms.g107.com/integral.php/Api/get_signature',
  20. corpId:'',
  21. },
  22. //获取积分类型
  23. getTypes() {
  24. this.$get("api/integral/types", {}).then((res) => {
  25. this.globalData.types = res.data.data.list;
  26. })
  27. },
  28. //封装post
  29. $post(url, data={}) {
  30. const promise = new Promise(function (resolve, reject) {
  31. dd.httpRequest({
  32. url: baseUrl + url,
  33. method: 'POST',
  34. headers: {
  35. 'Content-Type': 'application/x-www-form-urlencoded',
  36. 'A-Token': that.globalData.token
  37. },
  38. data: data,
  39. dataType: 'json',
  40. success: function (res) {
  41. if (res.data.code == 1) {
  42. if (res.refresh_token && res.data.refresh_token != that.globalData.token) {
  43. that.globalData.token = res.data.refresh_token
  44. }
  45. resolve(res);
  46. } else if (res.data.code == 401) {
  47. that.globalData.showToast("登录已过期");
  48. reject(res);
  49. } else {
  50. that.globalData.showToast(res.data.msg);
  51. reject(res);
  52. }
  53. },
  54. fail: function (res) {
  55. reject(res);
  56. }
  57. });
  58. })
  59. return promise;
  60. },
  61. //封装get
  62. $get(url,data={},Accept) {
  63. const promise = new Promise(function (resolve, reject) {
  64. dd.showLoading();
  65. dd.httpRequest({
  66. url: baseUrl + url,
  67. method: 'GET',
  68. headers: {
  69. 'Content-Type': 'application/x-www-form-urlencoded',
  70. 'A-Token': that.globalData.token,
  71. 'Accept': Accept ? Accept:''
  72. },
  73. data: data,
  74. dataType: 'json',
  75. success: function (res) {
  76. dd.hideLoading();
  77. if (res.data.code == 1) {
  78. if (res.data.refresh_token && res.data.refresh_token != that.globalData.token) {
  79. that.globalData.token = res.data.refresh_token
  80. }
  81. resolve(res);
  82. } else if (res.data.code == 401) {
  83. that.globalData.showToast("登录已过期");
  84. // reject(res);
  85. } else {
  86. that.globalData.showToast(res.data.msg)
  87. // reject(res);
  88. }
  89. },
  90. fail: function (res) {
  91. dd.hideLoading();
  92. reject(res);
  93. },
  94. });
  95. })
  96. return promise;
  97. },
  98. //免登
  99. login(corpId, callBack) {
  100. dd.getAuthCode({
  101. success: function (res) {
  102. console.log(res);
  103. that.$post('api/ding/login', { authCode: res.authCode, corpId: corpId }).then(res => {
  104. if (res.data.code == 1) {
  105. var { token, user } = res.data.data;
  106. that.globalData.token = token;
  107. that.globalData.userData = user;
  108. callBack();
  109. } else {
  110. that.globalData.showToast(res.msg)
  111. }
  112. }).catch(err=>{
  113. console.log(err);
  114. })
  115. },
  116. fail:function(err){
  117. console.log(err)
  118. }
  119. });
  120. },
  121. getTypesItem(id){
  122. return getTypeItem(this.globalData.types,id);
  123. },
  124. onLaunch(options) {
  125. that = this;
  126. that.getTypes();
  127. that.globalData.corpId = options.query.corpId;
  128. },
  129. });