app.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. month_tow:formatTime(new Date()).month_tow,//当前月份
  20. types: [],
  21. userData: '',
  22. token: '',
  23. // token:' eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvZGluZy5pbnN5cy5nMTA3LmNvbVwvYXBpXC9kaW5nXC9sb2dpbiIsImlhdCI6MTYwMDMxNDM0NywiZXhwIjoxNjAwOTE0MzQ3LCJuYmYiOjE2MDAzMTQzNDcsImp0aSI6IjgwMFJUS0J4RllIbnU5M3EiLCJzdWIiOjIsInBydiI6ImNhNjQ4OWQ1MGYyNDA3YTY3ODMwZTgwOTBkMDE0ODgzNTY4NTk2MmIiLCJyb2xlIjoiZW1wbG95ZWUifQ.E1RiQ6uMRICoL-2qDTeh5j5y-QLaUsGGs6PYLm-_1m8',
  24. ALIOSS_URL: 'https://integralsys.oss-cn-shenzhen.aliyuncs.com',
  25. imgHttpUrl: 'https://intesys.cms.g107.com/integral.php/Api/get_signature',
  26. corpId: '',
  27. yearArr: yearArr,
  28. isAdministrator: false,//是否管理员
  29. isCreator: false,//是否是创始人
  30. corpMessage: '',//企业套餐信息
  31. },
  32. //获取积分类型
  33. getTypes(callBack) {
  34. this.$get("api/integral/types", {}).then((res) => {
  35. this.globalData.types = res.data.data.list;
  36. callBack();
  37. })
  38. },
  39. //获取套餐信息
  40. getCorp(corpId) {
  41. this.$get("api/order/corp", { corp_id: corpId }).then((res) => {
  42. this.globalData.corpMessage = res.data.data;
  43. })
  44. },
  45. routerGet2(url, data = {}, Accept) {
  46. return new Promise(function (resolve, reject) {
  47. dd.httpRequest({
  48. url: baseUrl + url,
  49. method: 'GET',
  50. headers: {
  51. 'Content-Type': 'application/x-www-form-urlencoded',
  52. 'A-Token': that.globalData.token,
  53. 'Accept': Accept ? Accept : ''
  54. },
  55. data: data,
  56. dataType: 'json',
  57. success: function (res) {
  58. if (res.data.code == 1) {
  59. if (res.data.refresh_token && res.data.refresh_token != that.globalData.token) {
  60. that.globalData.token = res.data.refresh_token
  61. }
  62. resolve(res);
  63. } else if (res.data.code == 401) {
  64. that.globalData.showToast("登录已过期");
  65. // reject(res);
  66. } else {
  67. that.globalData.showToast(res.data.msg)
  68. // reject(res);
  69. }
  70. },
  71. fail: function (res) {
  72. if (res.errorMessage == 'NETWORK ERROR') {
  73. dd.alert({
  74. title: '网络异常',
  75. content: '网络异常,请检查网络是否畅通,再重新进入应用',
  76. buttonText: '我知道了',
  77. success: () => { },
  78. });
  79. return;
  80. }
  81. reject(res);
  82. }
  83. });
  84. })
  85. },
  86. routerGet(url, data = {}, Accept) {
  87. return new Promise(function (resolve, reject) {
  88. dd.showLoading();
  89. dd.httpRequest({
  90. url: baseUrl + url,
  91. method: 'GET',
  92. headers: {
  93. 'Content-Type': 'application/x-www-form-urlencoded',
  94. 'A-Token': that.globalData.token,
  95. 'Accept': Accept ? Accept : ''
  96. },
  97. data: data,
  98. dataType: 'json',
  99. success: function (res) {
  100. if (res.data.code == 1) {
  101. if (res.data.refresh_token && res.data.refresh_token != that.globalData.token) {
  102. that.globalData.token = res.data.refresh_token
  103. }
  104. resolve(res);
  105. } else if (res.data.code == 401) {
  106. that.globalData.showToast("登录已过期");
  107. // reject(res);
  108. } else {
  109. that.globalData.showToast(res.data.msg)
  110. // reject(res);
  111. }
  112. },
  113. fail: function (res) {
  114. if (res.errorMessage == 'NETWORK ERROR') {
  115. dd.alert({
  116. title: '网络异常',
  117. content: '网络异常,请检查网络是否畅通,再重新进入应用',
  118. buttonText: '我知道了',
  119. success: () => { },
  120. });
  121. return;
  122. }
  123. reject(res);
  124. },
  125. complete: function () {
  126. dd.hideLoading();
  127. }
  128. });
  129. })
  130. },
  131. routerPost(url, data = {}, Accept) {
  132. return new Promise(function (resolve, reject) {
  133. dd.httpRequest({
  134. url: baseUrl + url,
  135. method: 'POST',
  136. headers: {
  137. 'Content-Type': 'application/x-www-form-urlencoded',
  138. 'A-Token': that.globalData.token,
  139. 'Accept': Accept ? Accept : ''
  140. },
  141. data: data,
  142. dataType: 'json',
  143. success: function (res) {
  144. if (res.data.code == 1) {
  145. if (res.refresh_token && res.data.refresh_token != that.globalData.token) {
  146. that.globalData.token = res.data.refresh_token
  147. }
  148. resolve(res);
  149. } else if (res.data.code == 401) {
  150. that.globalData.showToast("登录已过期");
  151. reject(res);
  152. } else {
  153. that.globalData.showToast(res.data.msg);
  154. reject(res);
  155. }
  156. },
  157. fail: function (res) {
  158. if (res.errorMessage == 'NETWORK ERROR') {
  159. dd.alert({
  160. title: '网络异常',
  161. content: '网络异常,请检查网络是否畅通,再重新进入应用',
  162. buttonText: '我知道了',
  163. success: () => { },
  164. });
  165. return;
  166. }
  167. reject(res);
  168. }
  169. });
  170. })
  171. },
  172. //封装post
  173. $post(url, data = {}, Accept) {
  174. if (url == 'api/ding/login') {
  175. return that.routerPost(url, data, Accept);
  176. }
  177. if (!that.globalData.token) {
  178. dd.navigateTo({
  179. url: '../../init/init'
  180. })
  181. return Promise.reject("登录中")
  182. } else {
  183. return that.routerPost(url, data, Accept);
  184. }
  185. },
  186. //封装get
  187. $get(url, data = {}, Accept) {
  188. if (url == 'api/integral/types' || url == 'api/order/corp') {
  189. return that.routerGet(url, data, Accept);
  190. }
  191. if (!that.globalData.token) {
  192. dd.navigateTo({
  193. url: '../../init/init'
  194. })
  195. return Promise.reject("登录中")
  196. } else {
  197. return that.routerGet(url, data, Accept);
  198. }
  199. },
  200. //封装get
  201. $get2(url, data = {}, Accept) {
  202. if (url == 'api/integral/types' || url == 'api/order/corp') {
  203. return that.routerGet2(url, data, Accept);
  204. }
  205. if (!that.globalData.token) {
  206. dd.navigateTo({
  207. url: '../../init/init'
  208. })
  209. return Promise.reject("登录中")
  210. } else {
  211. return that.routerGet2(url, data, Accept);
  212. }
  213. },
  214. //免登
  215. login(corpId, callBack) {
  216. dd.getAuthCode({
  217. success: function (res) {
  218. // console.log(res.authCode,corpId)
  219. // return;
  220. that.$post('api/ding/login', { authCode: res.authCode, corpId: corpId }).then(res => {
  221. if (res.data.code == 1) {
  222. var { token, user } = res.data.data;
  223. var isStart = false;
  224. if (user.is_official == 1) {
  225. user.employee_detail.role_list.forEach(item => {
  226. if (item.name == 'creator') {
  227. that.globalData.isCreator = true;
  228. isStart = true;
  229. }
  230. if (item.name == 'admin' || item.name == 'creator' || item.name == 'point_manager'||item.name=='dept_manager') {
  231. that.globalData.isAdministrator = true;
  232. }
  233. });
  234. that.globalData.token = token;
  235. that.globalData.userData = user;
  236. var getIsStart = dd.getStorageSync({ key: 'isStart' });//判断是否需要打开引导页
  237. // console.log(JSON.stringify(user));
  238. if (isStart && !getIsStart.data) {//判断是否需要打开引导
  239. dd.reLaunch({
  240. url: '../../start/start'
  241. })
  242. } else {
  243. callBack(true);
  244. }
  245. } else {
  246. callBack(false);
  247. }
  248. } else if (res.data.code == 3000) {
  249. that.globalData.showToast("员工信息同步中,请稍后进入")
  250. } else {
  251. that.globalData.showToast(res.msg)
  252. }
  253. }).catch(err => {
  254. console.log(err);
  255. })
  256. },
  257. fail: function (err) {
  258. console.log(err)
  259. }
  260. });
  261. },
  262. getTypesItem(id) {
  263. return getTypeItem(this.globalData.types, id);
  264. },
  265. onLaunch(options) {
  266. that = this;
  267. that.getTypes(function () { });
  268. that.getCorp(options.query.corpId);
  269. that.globalData.corpId = options.query.corpId;
  270. },
  271. });