app.js 4.3 KB

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