app.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. isAdministrator:false,//是否管理员
  28. },
  29. //获取积分类型
  30. getTypes(callBack) {
  31. this.$get("api/integral/types", {}).then((res) => {
  32. this.globalData.types = res.data.data.list;
  33. callBack();
  34. })
  35. },
  36. routerGet(url,data={},Accept){
  37. return new Promise(function (resolve, reject) {
  38. dd.showLoading();
  39. dd.httpRequest({
  40. url: baseUrl + url,
  41. method: 'GET',
  42. headers: {
  43. 'Content-Type': 'application/x-www-form-urlencoded',
  44. 'A-Token': that.globalData.token,
  45. 'Accept': Accept ? Accept:''
  46. },
  47. data: data,
  48. dataType: 'json',
  49. success: function (res) {
  50. if (res.data.code == 1) {
  51. if (res.data.refresh_token && res.data.refresh_token != that.globalData.token) {
  52. that.globalData.token = res.data.refresh_token
  53. }
  54. resolve(res);
  55. } else if (res.data.code == 401) {
  56. that.globalData.showToast("登录已过期");
  57. // reject(res);
  58. } else {
  59. that.globalData.showToast(res.data.msg)
  60. // reject(res);
  61. }
  62. },
  63. fail: function (res) {
  64. reject(res);
  65. },
  66. complete:function(){
  67. dd.hideLoading();
  68. }
  69. });
  70. })
  71. },
  72. routerPost(url,data={}){
  73. return new Promise(function (resolve, reject) {
  74. dd.httpRequest({
  75. url: baseUrl + url,
  76. method: 'POST',
  77. headers: {
  78. 'Content-Type': 'application/x-www-form-urlencoded',
  79. 'A-Token': that.globalData.token
  80. },
  81. data: data,
  82. dataType: 'json',
  83. success: function (res) {
  84. if (res.data.code == 1) {
  85. if (res.refresh_token && res.data.refresh_token != that.globalData.token) {
  86. that.globalData.token = res.data.refresh_token
  87. }
  88. resolve(res);
  89. } else if (res.data.code == 401) {
  90. that.globalData.showToast("登录已过期");
  91. reject(res);
  92. } else {
  93. that.globalData.showToast(res.data.msg);
  94. reject(res);
  95. }
  96. },
  97. fail: function (res) {
  98. reject(res);
  99. }
  100. });
  101. })
  102. },
  103. //封装post
  104. $post(url, data={}) {
  105. if(url=='api/ding/login'){
  106. return that.routerPost(url,data);
  107. }
  108. if(!that.globalData.token){
  109. dd.navigateTo({
  110. url:'../../init/init'
  111. })
  112. return Promise.reject("登录中")
  113. }else{
  114. return that.routerPost(url,data);
  115. }
  116. },
  117. //封装get
  118. $get(url,data={},Accept) {
  119. if(url=='api/integral/types'){
  120. return that.routerGet(url,data,Accept);
  121. }
  122. if(!that.globalData.token){
  123. dd.navigateTo({
  124. url:'../../init/init'
  125. })
  126. return Promise.reject("登录中")
  127. }else{
  128. return that.routerGet(url,data,Accept);
  129. }
  130. },
  131. //免登
  132. login(corpId, callBack) {
  133. dd.getAuthCode({
  134. success: function (res) {
  135. that.$post('api/ding/login', { authCode: res.authCode, corpId: corpId }).then(res => {
  136. if (res.data.code == 1) {
  137. var { token, user } = res.data.data;
  138. if(user.is_official==1){
  139. user.employee_detail.role_list.forEach(item => {
  140. if (item.name == 'admin' || item.name == 'creator' || item.name == 'point_manager') {
  141. that.globalData.isAdministrator = true;
  142. }
  143. });
  144. that.globalData.token = token;
  145. that.globalData.userData = user;
  146. callBack(true);
  147. }else{
  148. callBack(false);
  149. }
  150. }else if(res.data.code == 3000){
  151. that.globalData.showToast("员工信息同步中,请稍后进入")
  152. }else{
  153. that.globalData.showToast(res.msg)
  154. }
  155. }).catch(err=>{
  156. console.log(err);
  157. })
  158. },
  159. fail:function(err){
  160. console.log(err)
  161. }
  162. });
  163. },
  164. getTypesItem(id){
  165. return getTypeItem(this.globalData.types,id);
  166. },
  167. onLaunch(options) {
  168. that = this;
  169. that.getTypes(function(){});
  170. that.globalData.corpId = options.query.corpId;
  171. },
  172. });