config.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. ;
  2. !(function(win) {
  3. "use strict";
  4. var pcLogin = function(){
  5. let path = top.location.pathname.split('/');
  6. path.splice(-1,1,'');
  7. path = path.join('/');
  8. console.log(path + 'login/');
  9. top.location.href = path + 'login/';
  10. return true;
  11. };
  12. window.hywa = {
  13. config: {
  14. href: '/buyer-side-web',
  15. // href: 'http://172.16.90.125:8765',
  16. port: {
  17. login: '/user/pcLogin', //登录
  18. loginOut: "/user/pcLogout", //退出
  19. mainMenu: '/menu/sysMenuTree', //获取左侧菜单
  20. changePassword: "/user/changePwd", //修改密码
  21. check_userPhone: "/login/userCheck", //检验手机号
  22. mainInfo: '/user/findSysInfoByUserId', //主页信息
  23. uploadFileUrl: '/file/upload', //上传图片
  24. getMenuBtn: '/menu/getButton', //获取菜单按钮
  25. // 农产品
  26. productTableUrl: '/product/findProductByWebFrom',
  27. productBigTypeUrl: '/dict',
  28. productSmallTypeUrl: '/dict/productSmallType',
  29. productAddFormUrl: '/product',
  30. productUpdateFormUrl: '/product/update',
  31. productStatusUrl: '/product/onOff',
  32. productByIdUrl: '/product',
  33. del_productTableData: '/product',
  34. // 店铺
  35. shopTableUrl: '/sellerInfo',
  36. shopStatusUrl: '/sellerInfo/isAvailable',
  37. shopByIdUrl: '/sellerInfo',
  38. // 用户-买家
  39. userTableUrl: '/buyer/buyerList',
  40. userByIdUrl: '/buyer/examine',
  41. userStatusUrl: '/buyer/onOff',
  42. // 骑手
  43. riderTableUrl: '/rider',
  44. riderAddFormUrl: '/rider',
  45. riderUpdateFormUrl: '/rider',
  46. riderByIdUrl: '/product',
  47. riderDelUrl: '/rider',
  48. riderStatusUrl: '/rider/available',
  49. // 消息发布
  50. mesTableUrl: '/announcement/findAnnouncementInfoAll',
  51. mesStatusUrl: '/announcement/available',
  52. mesFormUrl: '/announcement/saveOrUpdate',
  53. mesByIdUrl: '/announcement/findAnnouncementById',
  54. imgContentUpload: '/file/uploadImage',
  55. show_img: '/file/showImage?filePath=',
  56. // 交易统计
  57. tradeTableUrl: '/analysis/transaction/list',
  58. shopsTableUrl: '/analysis/seller/list',
  59. tradeTotalUrl: '/analysis/transaction',
  60. shopsTotalUrl: '/analysis/seller',
  61. tradeExportUrl: '/analysis/transaction/excel',
  62. shopExportUrl: '/analysis/seller/excel',
  63. // 访客分析
  64. visitorTableUrl: '/analysis/customer',
  65. viewsVolumeUrl: '/analysis/views',
  66. // 排行榜
  67. goodsTableUrl: '/analysis/product/leaderboard',
  68. sellerTableUrl: '/analysis/seller/leaderboard',
  69. // 单品分析
  70. singleGoodsTotalUrl: '/analysis/product',
  71. singleGoodsTableUrl: '/analysis/product/details',
  72. singleOrderVolumeUrl: '/analysis/orders',
  73. multiTypeSelect: "/dict", //参数多条件查询
  74. getProvince: "/region/province/index", //获取省
  75. getCity: "/region/city/index", //获取市
  76. getCounty: "/region/county/index", //获取县
  77. // 订单
  78. purchaseOrderTableUrl: "/orderInfo/list",
  79. flowOrderTableUrl: "/transferOrder/findByOrderId",
  80. orderByIdUrl: '/orderInfo/orderDetails',
  81. // 骑手取货
  82. riderPickTableUrl: '/transferOrder/list',
  83. //费用设置
  84. costsSetUrl:'/costsSet',
  85. // 权限
  86. userList: "/user/findAll", //用户列表
  87. userAddNew: "/user", //添加用户
  88. delete_newAddUser: "/user", //删除用户
  89. select_user: "/user/findById", //查询用户
  90. forbidUser: '/user/disableUser', //禁止用户
  91. purchaseUserList: '/user/findSpotName', //获取用户收购点信息
  92. regionListUrl: '/area/search',
  93. regionFormUrl: '/area',
  94. roleDataList: "/role/getAll", //获取角色列表
  95. roleListUrl: '/role/getAll',
  96. roleFormUrl: '/role',
  97. roleByid: '/role/findById',
  98. menuListUrl: '/menu/getMenuByRole',
  99. menuFormUrl: '/menu/saveRoleMenu',
  100. }
  101. },
  102. sessionTable: {
  103. tableName: 'system',
  104. userData: 'userData',
  105. },
  106. jumpPage: {
  107. home: "../index.html",
  108. login: 'login/'
  109. },
  110. codeVerify: {
  111. 401: pcLogin,
  112. 402: pcLogin,
  113. 403: pcLogin,
  114. 404: pcLogin,
  115. 405: pcLogin,
  116. 1004: function() {
  117. return true;
  118. },
  119. 2006: function() {
  120. return false;
  121. },
  122. default: function() {
  123. return true;
  124. }
  125. },
  126. //字体库,layui样式,自己的公共样式,所有页面样式
  127. css: ['iconfont/iconfont.css', 'layui/css/layui.css', 'css/common.css'],
  128. //需要加载的js
  129. js: []
  130. };
  131. //加载样式
  132. link(window.hywa.css);
  133. //加载JS
  134. require(window.hywa.js);
  135. win.hijack = function() {
  136. var _this = this;
  137. layui.use(['layer'], function() {
  138. _this.layer = layui.layer;
  139. });
  140. _this.json = {
  141. code: -404,
  142. msg: "返回数据格式错误",
  143. count: 0,
  144. data: []
  145. };
  146. };
  147. win.hijack.prototype.onload = function(xhr) {
  148. var _this = this;
  149. if (xhr.readyState === 4) { // 成功完成
  150. // 判断响应结果:
  151. if (xhr.status === 200) {
  152. //layer.close(xhr.xhr.lay_loading);
  153. xhr.responseText = JSON.stringify(_this.changeJSON(xhr.responseText).json);
  154. switch (_this.json.code) {
  155. case 0:
  156. // return _this.okMsg(_this.json.msg);
  157. return false;
  158. default:
  159. return _this.errorMsg(_this.json.code, _this.json.msg);
  160. };
  161. } else {
  162. return _this.errorMsg(xhr.status);
  163. }
  164. } else if (xhr.readyState === 1) {
  165. xhr.setRequestHeader('x-requested-with', "XMLHttpRequest");
  166. } else {
  167. }
  168. };
  169. win.hijack.prototype.open = function(arg, xhr) {
  170. var _this = this;
  171. _this.url = location.searchObj(arg[1]);
  172. //xhr.lay_loading = layer.load(0, {shade: false});
  173. try {
  174. if (!_this.url.userId) {
  175. var token = layui.sessionData(window.hywa.sessionTable.tableName);
  176. _this.url.userId = (JSON.stringify(token) != '{}' ? token.userData.userId : false);
  177. }
  178. } catch (e) {
  179. }
  180. // debugger
  181. _this.url.pageNum = _this.url.page - 0;
  182. _this.url.pageSize = _this.url.limit - 0;
  183. _this.url.pageNum || (delete _this.url.pageNum);
  184. _this.url.pageSize || (delete _this.url.pageSize);
  185. _this.url.pageNum && (delete _this.url.page);
  186. _this.url.pageSize && (delete _this.url.limit);
  187. arg[1] = _this.changeUrl(_this.url, arg[1].split('?')[0]).url;
  188. };
  189. win.hijack.prototype.changeUrl = function(obj, url) {
  190. var _this = this;
  191. _this.url = (_this.httpVerify(url) ? (function() {
  192. return _this.httpVerify(hywa.config.port[url]) ? hywa.config.href + hywa.config.port[url] : hywa.config.port[
  193. url];
  194. })() : url);
  195. console.log("url", _this.url += "?");
  196. for (var i in obj) {
  197. _this.url += i + "=" + obj[i] + "&";
  198. }
  199. _this.url = _this.url.substr(0, _this.url.length - 1);
  200. return this;
  201. };
  202. win.hijack.prototype.httpVerify = function(url) {
  203. return (url.substr(0, 5) != 'http:' && url.substr(0, 6) != 'https:' && url.substr(0, 2) != '//');
  204. };
  205. win.hijack.prototype.changeJSON = function(json) {
  206. var _this = this;
  207. try {
  208. json = JSON.parse(json);
  209. if (json.retHead) {
  210. _this.json.code = json.retHead.errCode;
  211. _this.json.msg = json.retHead.errMsg || "不知道怎么了!!!";
  212. }
  213. if (json.retBody && !!json.retBody.list && !!json.retBody.list.length) {
  214. _this.json.count = json.retBody.total || 0;
  215. _this.json.data = json.retBody.list || [];
  216. } else if (json.retBody != "null" && !!json.retBody && Array.isArray(json.retBody.list) && !json.retBody.total) {
  217. _this.json.data = [];
  218. } else {
  219. _this.json.data = Array.isArray(json.retBody) ? (function() {
  220. _this.json.count = json.retBody.length;
  221. return json.retBody;
  222. })() : (json.retBody != 'null' ? [json.retBody] : []);
  223. }
  224. } catch (e) {
  225. _this.json = {
  226. code: -404,
  227. msg: "返回数据格式错误",
  228. count: 0,
  229. data: []
  230. };
  231. }
  232. return this;
  233. };
  234. win.hijack.prototype.errorMsg = function(code, msg) {
  235. var _this = this;
  236. _this.layer.msg("(" + code + ") " + (msg || "服务器通讯不畅!"), {
  237. icon: 2,
  238. time: 3000
  239. });
  240. return (window.hywa.codeVerify[(code - 0 || 'default')] || window.hywa.codeVerify['default'])();
  241. };
  242. win.hijack.prototype.okMsg = function(msg) {
  243. var _this = this;
  244. _this.layer.msg(msg, {
  245. icon: 1,
  246. time: 800
  247. });
  248. return false;
  249. };
  250. win.hijack.prototype.setRequestHeader = function(xhr) {
  251. var _this = this;
  252. if (typeof xhr.RequestHeader == 'undefined') {
  253. xhr.RequestHeader = true;
  254. var token = layui.sessionData(window.hywa.sessionTable.tableName);
  255. xhr.setRequestHeader('accessToken', (JSON.stringify(token) != '{}' ? token.token : false));
  256. }
  257. };
  258. var hook = new hijack();
  259. hookAjax({
  260. //拦截函数
  261. open: function(arg) {
  262. return hook.open(arg, this.xhr);
  263. },
  264. //拦截回调
  265. onreadystatechange: function(xhr) {
  266. // console.log(xhr.readyState)
  267. return hook.onload(xhr);
  268. },
  269. onload: function(xhr) {
  270. return hook.onload(xhr);
  271. },
  272. setRequestHeader: function(h, xhr) {
  273. // console.log("加头",JSON.stringify(xhr));
  274. hook.setRequestHeader(xhr);
  275. }
  276. });
  277. })(window);
  278. /**
  279. * 时间格式化
  280. */
  281. Date.prototype.format = function(format) {
  282. var date = {
  283. "M+": this.getMonth() + 1,
  284. "d+": this.getDate(),
  285. "h+": this.getHours(),
  286. "m+": this.getMinutes(),
  287. "s+": this.getSeconds(),
  288. "q+": Math.floor((this.getMonth() + 3) / 3),
  289. "S+": this.getMilliseconds()
  290. };
  291. if (/(y+)/i.test(format)) {
  292. format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  293. }
  294. for (var k in date) {
  295. if (new RegExp("(" + k + ")").test(format)) {
  296. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
  297. date[k] : ("00" + date[k]).substr(("" + date[k]).length));
  298. }
  299. }
  300. return format;
  301. }
  302. /**
  303. * URL参数转换为对象
  304. */
  305. Location.prototype.searchObj = function(url) {
  306. var obj = {};
  307. var arr = (url || this.search).match(/[?&][^?&]+=[^?&]+/g);
  308. if (arr) {
  309. arr.forEach(function(item) {
  310. var tempArr = item.substring(1).split('=');
  311. obj[decodeURIComponent(tempArr[0])] = decodeURIComponent(tempArr[1]);
  312. length++;
  313. });
  314. }
  315. return obj;
  316. }