app.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. allDate: formatTime(new Date()).allDate,//带时分
  21. types: [],
  22. userData: '',
  23. token: '',
  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 if (res.data.code == 2001) {
  153. reject(res);
  154. } else {
  155. that.globalData.showToast(res.data.msg);
  156. reject(res);
  157. }
  158. },
  159. fail: function (res) {
  160. if (res.errorMessage == 'NETWORK ERROR') {
  161. dd.alert({
  162. title: '网络异常',
  163. content: '网络异常,请检查网络是否畅通,再重新进入应用',
  164. buttonText: '我知道了',
  165. success: () => { },
  166. });
  167. return;
  168. }
  169. reject(res);
  170. }
  171. });
  172. })
  173. },
  174. //封装post
  175. $post(url, data = {}, Accept) {
  176. // if (url == 'api/ding/login') {
  177. // return that.routerPost(url, data, Accept);
  178. // }
  179. // if (!that.globalData.token) {
  180. // dd.navigateTo({
  181. // url: '../../init/init'
  182. // })
  183. // return Promise.reject("登录中")
  184. // } else {
  185. return that.routerPost(url, data, Accept);
  186. // }
  187. },
  188. //封装get
  189. $get(url, data = {}, Accept) {
  190. // if (url == 'api/integral/types' || url == 'api/order/corp') {
  191. // return that.routerGet(url, data, Accept);
  192. // }
  193. // if (!that.globalData.token) {
  194. // dd.navigateTo({
  195. // url: '../../init/init'
  196. // })
  197. // return Promise.reject("登录中")
  198. // } else {
  199. return that.routerGet(url, data, Accept);
  200. // }
  201. },
  202. //封装get
  203. $get2(url, data = {}, Accept) {
  204. // if (url == 'api/integral/types' || url == 'api/order/corp') {
  205. // return that.routerGet2(url, data, Accept);
  206. // }
  207. // if (!that.globalData.token) {
  208. // dd.navigateTo({
  209. // url: '../../init/init'
  210. // })
  211. // return Promise.reject("登录中")
  212. // } else {
  213. return that.routerGet2(url, data, Accept);
  214. // }
  215. },
  216. //免登
  217. login(corpId, callBack,errBack) {
  218. if (that.globalData.token) {
  219. callBack(true)
  220. } else {
  221. dd.getAuthCode({
  222. success: function (res) {
  223. that.$post('api/ding/login', { authCode: res.authCode, corpId: corpId }).then(res => {
  224. if (res.data.code == 1) {
  225. var { token, user } = res.data.data;
  226. var isStart = false;
  227. if (user.is_official == 1) {
  228. user.employee_detail.role_list.forEach(item => {
  229. if (item.name == 'creator') {
  230. that.globalData.isCreator = true;
  231. isStart = true;
  232. }
  233. if (item.name == 'admin' || item.name == 'creator' || item.name == 'point_manager' || item.name == 'dept_manager') {
  234. that.globalData.isAdministrator = true;
  235. }
  236. });
  237. that.globalData.token = token;
  238. that.globalData.userData = user;
  239. var getIsStart = dd.getStorageSync({ key: 'isStart' });//判断是否需要打开引导页
  240. // console.log(JSON.stringify(user));
  241. if (isStart && !getIsStart.data) {//判断是否需要打开引导
  242. dd.reLaunch({
  243. url: '../../start/start'
  244. })
  245. } else {
  246. callBack(true);
  247. }
  248. } else {
  249. callBack(false);
  250. }
  251. } else if (res.data.code == 3000) {
  252. that.globalData.showToast("员工信息同步中,请稍后进入")
  253. } else {
  254. that.globalData.showToast(res.msg)
  255. }
  256. }).catch(err => {
  257. // errBack(err.data.code);
  258. // return
  259. if (err.data.code == 2001) {
  260. dd.confirm({
  261. title: '尊敬的用户',
  262. content: '您当前的套餐已到期',
  263. confirmButtonText: '去续费',
  264. cancelButtonText: '暂不需要',
  265. success: (result) => {
  266. if (result.confirm) {
  267. dd.reLaunch({
  268. url: `../../deploy/addMoney/addMoney`
  269. })
  270. }
  271. },
  272. });
  273. }
  274. })
  275. },
  276. fail: function (err) {
  277. console.log(err)
  278. }
  279. });
  280. }
  281. },
  282. getTypesItem(id) {
  283. return getTypeItem(this.globalData.types, id);
  284. },
  285. onLaunch(options) {
  286. that = this;
  287. that.getTypes(function () { });
  288. that.getCorp(options.query.corpId);
  289. that.globalData.corpId = options.query.corpId;
  290. },
  291. });