app.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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://new.gdy.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:[{id: 1, name: "绩效分", code: "JX"}, {id: 2, name: "A分", code: "AF"}, {id: 3, name: "B分", code: "BF"}],
  15. // token: ' eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjAuNzkuNC4xNjI6NDkxNTJcL2FwaVwvZW1wbG95ZWUtbG9naW4iLCJpYXQiOjE1OTY0NDIyNjksImV4cCI6MTU5OTAzNDI2OSwibmJmIjoxNTk2NDQyMjY5LCJqdGkiOiJEdmhPTzNhNVgyaFVoa2h4Iiwic3ViIjo2MTYsInBydiI6ImNhNjQ4OWQ1MGYyNDA3YTY3ODMwZTgwOTBkMDE0ODgzNTY4NTk2MmIiLCJyb2xlIjoiZW1wbG95ZWUifQ.2nR9w7omCOcJyHFFoiQPvdhp3sKrQt2FQb0mJYQ9mWo',
  16. // token:' eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjAuNzkuNC4xNjI6NDkxNTJcL2FwaVwvZW1wbG95ZWUtbG9naW4iLCJpYXQiOjE1OTY2NzcxNzUsImV4cCI6MTU5OTI2OTE3NSwibmJmIjoxNTk2Njc3MTc1LCJqdGkiOiI3aHRwSG5CTmJ3bjJrOVZhIiwic3ViIjoxMjMwLCJwcnYiOiJjYTY0ODlkNTBmMjQwN2E2NzgzMGU4MDkwZDAxNDg4MzU2ODU5NjJiIiwicm9sZSI6ImVtcGxveWVlIn0.Kfu2D8S1mloqHfyiYPLKwzDh6QYGMHfuwpFqos6A60g',
  17. userData: {},
  18. token:' eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC90ZXN0LWRpbmcuZzEwNy5jb21cL2FwaVwvdGVzdCIsImlhdCI6MTU5NzAyMDUyOCwiZXhwIjoxNTk3NjIwNTI4LCJuYmYiOjE1OTcwMjA1MjgsImp0aSI6Im1CbFhqemJuUm1sRlVxdkEiLCJzdWIiOjE2LCJwcnYiOiJjYTY0ODlkNTBmMjQwN2E2NzgzMGU4MDkwZDAxNDg4MzU2ODU5NjJiIiwicm9sZSI6ImVtcGxveWVlIn0.LNZmvfTE8rDfO4KQ1aONHMA0rT1ACsxbWOjDIOXVZJs',
  19. ALIOSS_URL: 'https://integralsys.oss-cn-shenzhen.aliyuncs.com',
  20. imgHttpUrl:'https://intesys.cms.g107.com/integral.php/Api/get_signature',
  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. } else {
  49. that.globalData.showToast(res.data.msg);
  50. }
  51. },
  52. fail: function (res) {
  53. reject(res);
  54. }
  55. });
  56. })
  57. return promise;
  58. },
  59. //封装get
  60. $get(url, data,Accept) {
  61. const promise = new Promise(function (resolve, reject) {
  62. dd.showLoading();
  63. dd.httpRequest({
  64. url: baseUrl + url,
  65. method: 'GET',
  66. headers: {
  67. 'Content-Type': 'application/x-www-form-urlencoded',
  68. 'A-Token': that.globalData.token,
  69. 'Accept': Accept ? Accept:''
  70. },
  71. data: data,
  72. dataType: 'json',
  73. success: function (res) {
  74. if (res.data.code == 1) {
  75. if (res.data.refresh_token && res.data.refresh_token != that.globalData.token) {
  76. that.globalData.token = res.data.refresh_token
  77. }
  78. resolve(res);
  79. dd.hideLoading();
  80. } else if (res.data.code == 401) {
  81. that.globalData.showToast("登录已过期");
  82. // reject(res);
  83. } else {
  84. that.globalData.showToast(res.data.msg)
  85. // reject(res);
  86. }
  87. },
  88. fail: function (res) {
  89. reject(res);
  90. dd.hideLoading();
  91. },
  92. });
  93. })
  94. return promise;
  95. },
  96. //免登
  97. login(corpId, callBack) {
  98. dd.getAuthCode({
  99. success: function (res) {
  100. that.$post('api/ding/login', { authCode: res.authCode, corpId: corpId }).then(res => {
  101. if (res.data.code == 1) {
  102. var { token, user } = res.data.data;
  103. // that.globalData.token = token;
  104. that.globalData.userData = user;
  105. callBack();
  106. } else {
  107. that.globalData.showToast(res.msg)
  108. }
  109. })
  110. }
  111. });
  112. },
  113. getTypesItem(id){
  114. return getTypeItem(this.globalData.types,id);
  115. },
  116. onLaunch(options) {
  117. that = this;
  118. that.getTypes();
  119. that.globalData.corpId = options.query.corpId;
  120. },
  121. });