config.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. var SYS_VER = parseInt(Math.random() * 10000000000);
  2. function resetButton(menus, $) {
  3. var menuId = location.href.substring(location.href.indexOf("id=") + 3, location.href.indexOf("id=") + 35);
  4. for (var i = 0; i < menus.length; i++) {
  5. for (var j = 0; j < menus[i].subMenuList.length; j++) {
  6. if (menuId == menus[i].subMenuList[j].id) {
  7. var rights = menus[i].subMenuList[j].subMenuList;
  8. for (var k = 0; k < rights.length; k++) {
  9. if (rights[k].isChecked == 0) {
  10. $(rights[k].authStr.substring(rights[k].authStr.lastIndexOf(":") + 1) + "-btn-0").hide();
  11. }
  12. else {
  13. $(rights[k].authStr.substring(rights[k].authStr.lastIndexOf(":") + 1) + "-btn-0").show();
  14. }
  15. }
  16. break;
  17. }
  18. }
  19. }
  20. }
  21. function loadJS(url) {
  22. document.write("<scirpt src='" + url + "?ver=" + SYS_VER + "'></scirpt>")
  23. }
  24. !(function (win) {
  25. "use strict";
  26. window.hywa = {
  27. config: {
  28. href: 'http://172.16.90.64:21009/',
  29. imgbyapplets: 'http://47.98.47.246:8310',
  30. port: {
  31. login: '/web/user/login', //登录
  32. loginOut: "/web/user/logout", //退出
  33. changePassword: "/web/user/edit", //修改密码
  34. userList: "/web/user/searchByPage", //列表
  35. add_user: "/web/user/add", //添加
  36. edit_user: "/web/user/edit", //修改
  37. delete_user: "/web/user/del", //删除
  38. select_user: "/web/user/searchById", //查询单个
  39. forbidUser: '/web/user/forbidden', //禁止用户
  40. restPwd: "/web/user/restPwd",//重置密码
  41. //首页
  42. select_searchByPage: "/web/feedback/searchByPage",//评价明细列表
  43. del_feedback: "/web/feedback/batchDel",//删除评价
  44. qurey_echartTotal: "/web/code/record/statOneYear", //扫码图标统计
  45. query_listTotal: "/web/code/record/statYesterdayAndAllTime", //获取文字数统计
  46. //角色设置
  47. roleList: "/web/role/searchByPage", //获取角色列表
  48. add_role: "/web/role/add", //新增角色
  49. edit_role: "/web/role/edit", //修改角色
  50. delete_role: "/web/role/del", //修改角色
  51. select_role: "/web/role/searchById", //通过ID获取角色详细信息
  52. role_getAuth: "/web/role/searchRoleAuthInfo",//查询角色权限
  53. role_saveAuth: "/web/role/distrRoleAuthInfo",//保存企业授权信息
  54. //经销商管理
  55. dealerList: "/web/goods/dealer/searchByPage",
  56. add_dealer: "/web/goods/dealer/add",
  57. select_dealer: "/web/goods/dealer/findById",
  58. edit_dealer: "/web/goods/dealer/edit",
  59. delete_dealer: "/web/goods/dealer/delete",
  60. selectPId_dealer: "/web/goods/dealer/getCode",
  61. //企业
  62. orgList: "/web/org/searchByPage", //列表
  63. add_org: "/web/org/add", //添加
  64. edit_org: "/web/org/edit", //修改
  65. delete_org: "/web/org/del", //删除
  66. select_org: "/web/org/searchById", //查询单个
  67. select_Info_org: "/web/org/searchOrgInfo",//查询推广企业信息
  68. edit_Info_org: "/web/org/editExtendInfo",//企业推广保存
  69. org_getAuth: "/web/org/searchAuthInfo",//拉取企业授权信息
  70. org_saveAuth: "/web/org/distrOrgAuthInfo",//保存企业授权信息
  71. add_org_user: '/web/org/addOrgUser',//添加企业管理用户
  72. //产地
  73. regionList: "/web/goods/field/searchByPage", //列表
  74. add_region: "/web/goods/field/add", //添加
  75. edit_region: "/web/goods/field/edit", //修改
  76. delete_region: "/web/goods/field/del", //删除
  77. select_region: "/web/goods/field/searchById", //查询单个
  78. rnlist_region: "/web/goods/field/getBaseList",
  79. areaSearch: "/web/goods/field/getAreaInfo",//地址查询
  80. getOrchardList: "/web/goods/field/getOrchardList", // 获取原料生产数据
  81. //产品信息
  82. pdinfoList: "/web/goods/batch/searchByPage", //列表
  83. add_pdinfo: "/web/goods/batch/add", //添加
  84. add_rawMaterialInfo: "/web/inputs/save",//修改模式 - 添加原料项
  85. del_rawMaterialInfo: "/web/inputs/del",//修改模式 - 删除原料项
  86. add_produceProcessInfo: "/web/normal/save",//修改模式 - 添加生成过程项
  87. edit_produceProcessInfo: "/web/normal/edit",//修改模式 - 修改生成过程项
  88. del_produceProcessInfo: "/web/normal/del",//修改模式 - 删除生成过程项
  89. add_processingCirculationInfo: "/web/normal/save",//修改模式 - 添加加工流通过程项
  90. edit_processingCirculationInfo: "/web/normal/edit",//修改模式 - 修改加工流通过程项
  91. del_processingCirculationInfo: "/web/normal/del",//修改模式 - 删除加工流通过程项
  92. edit_pdinfo: "/web/goods/batch/edit", //修改
  93. delete_pdinfo: "/web/goods/batch/del", //删除
  94. select_pdinfo: "/web/goods/batch/searchById", //查询单个
  95. pdinfo2List: "/web/goods/searchByPage", //列表
  96. add_pdinfo2: "/web/goods/add", //添加
  97. edit_pdinfo2: "/web/goods/edit", //修改
  98. delete_pdinfo2: "/web/goods/del", //删除
  99. select_pdinfo2: "/web/goods/searchById", //查询单个
  100. pdinfo_qrcode: "/web/goods/batch/batchGoodsQRCode",//产品批次生成溯源码
  101. //溯源码管理
  102. qrcodeList: "/web/code/record/searchByPage", //列表
  103. view_qrcode: "/web/code/record/searchDetailById", //查看
  104. drop_qrcode: "/web/code/record/forbiddenCodeInfo", //废弃
  105. export_qrcode: "/web/code/record/exportDetailRecord", //导出
  106. delete_qrcode: "/web/code/record/delByPhysical", //删除
  107. drop_single: "/web/code/info/forbidden",//废弃单个溯源码
  108. show_codeDetail: "/web/code/record/showDetail",//溯源码预览
  109. print_qrcode: "/web/code/info/getPrintDetail", //溯源码打印
  110. setPrint_done: "/web/code/info/updateQRIsPrint",//标记已打印二维码
  111. //系统日志
  112. menuList: "/log/queryFuncName",//获取菜单列表
  113. logList: "/log/queryAll",//获取日志列表
  114. show_menu: "/menu/search", //查看权限菜单树
  115. get_menuList: "/menu/menuAllTree", //查看菜单列表
  116. select_menu: "/menu/search", //查看菜单详细,ID条件
  117. update_menu: "/menu", //菜单新增修改
  118. // 权限
  119. roleListUrl: '/role/getAll',
  120. roleFormUrl: '/role',
  121. roleByid: '/role/findById',
  122. menuListUrl: '/menu/getMenuByRole',
  123. menuFormUrl: '/menu/saveRoleMenu',
  124. systemListUrl: '/system/find',//系统维护查询
  125. systemFormUrl: '/system',//系统维护保存
  126. uploadImage: "/web/normal/uploadPics",
  127. }
  128. },
  129. sessionTable: {
  130. tableName: 'system',
  131. userData: 'userData'
  132. },
  133. jumpPage: {
  134. home: "../pages/?ver=" + SYS_VER,
  135. login: "../../?ver=" + SYS_VER
  136. },
  137. codeVerify: {
  138. 405: function () {
  139. console.log('logout')
  140. //top.location.href = window.hywa.jumpPage.login;
  141. return true;
  142. },
  143. 404: function () {
  144. // top.location.href = window.hywa.jumpPage.login;
  145. return true;
  146. },
  147. 500: function () {
  148. //top.location.href = window.hywa.jumpPage.login;
  149. return true;
  150. },
  151. 1004: function () {//认证失败
  152. top.location.href = window.hywa.jumpPage.login;
  153. return true;
  154. },
  155. 2010: function () {//不能修改删除自己
  156. return false;
  157. },
  158. 2011: function () {//不能对超级管理员进行操作
  159. return false;
  160. },
  161. 1002: function () {//密码错误
  162. return false;
  163. },
  164. 3003: function () {//修改前后密码不能相同
  165. return false;
  166. },
  167. 3004: function () {//修改前后密码不能相同
  168. return false;
  169. },
  170. 2006: function () {//文件上传失败
  171. return false;
  172. },
  173. 2002: function () {//参数不能为空
  174. return false;
  175. },
  176. 2003: function () {//类型被引用,请先删除引用
  177. return false;
  178. },
  179. 2004: function () {
  180. return false;
  181. },
  182. 2005: function () {//文件不能为空
  183. return false;
  184. },
  185. 3009: function () {
  186. return false;
  187. },
  188. 3008: function () {
  189. return false;
  190. },
  191. 3011: function () {
  192. return false;
  193. },
  194. 3017: function () {
  195. return true;
  196. },
  197. 3013: function () {
  198. return false;
  199. },
  200. 3019: function () {
  201. return false;
  202. },
  203. 3036: function () {
  204. return false;
  205. },
  206. 3037: function () {
  207. return false;
  208. },
  209. 3038: function () {
  210. return false;
  211. },
  212. 3039: function () {
  213. return false;
  214. },
  215. 3070: function () {
  216. return false;
  217. },
  218. default: function () {
  219. return false;
  220. }
  221. }
  222. };
  223. win.hijack = function () {
  224. var _this = this;
  225. layui.use(['layer'], function () {
  226. _this.layer = layui.layer;
  227. });
  228. _this.json = {
  229. code: -404,
  230. msg: "返回数据格式错误",
  231. count: 0,
  232. data: []
  233. };
  234. };
  235. win.hijack.prototype.onload = function (xhr) {
  236. var _this = this;
  237. if (xhr.readyState === 4) { // 成功完成
  238. // 判断响应结果:
  239. if (xhr.status === 200) {
  240. //layer.close(xhr.xhr.lay_loading);
  241. xhr.responseText = JSON.stringify(_this.changeJSON(xhr.responseText).json);
  242. switch (_this.json.code) {
  243. case 0:
  244. // return _this.okMsg(_this.json.msg);
  245. return false;
  246. default:
  247. return _this.errorMsg(_this.json.code, _this.json.msg);
  248. };
  249. } else {
  250. return _this.errorMsg(xhr.status);
  251. }
  252. } else if (xhr.readyState === 1) {
  253. xhr.setRequestHeader('x-requested-with', "XMLHttpRequest");
  254. } else {
  255. }
  256. };
  257. win.hijack.prototype.open = function (arg, xhr) {
  258. var _this = this;
  259. _this.url = location.searchObj(arg[1]);
  260. _this.url.pageNum = _this.url.page - 0;
  261. _this.url.pageSize = _this.url.limit - 0;
  262. _this.url.pageNum || (delete _this.url.pageNum);
  263. _this.url.pageSize || (delete _this.url.pageSize);
  264. _this.url.pageNum && (delete _this.url.page);
  265. _this.url.pageSize && (delete _this.url.limit);
  266. arg[1] = _this.changeUrl(_this.url, arg[1].split('?')[0]).url;
  267. };
  268. win.hijack.prototype.changeUrl = function (obj, url) {
  269. var _this = this;
  270. _this.url = (_this.httpVerify(url) ? (function () {
  271. return _this.httpVerify(hywa.config.port[url]) ? hywa.config.href + hywa.config.port[url] : hywa.config.port[url];
  272. })() : url);
  273. _this.url += "?";
  274. for (var i in obj) {
  275. _this.url += i + "=" + obj[i] + "&";
  276. }
  277. _this.url = _this.url.substr(0, _this.url.length - 1);
  278. return this;
  279. };
  280. win.hijack.prototype.httpVerify = function (url) {
  281. return (url.substr(0, 5) != 'http:' && url.substr(0, 6) != 'https:' && url.substr(0, 2) != '//');
  282. };
  283. win.hijack.prototype.changeJSON = function (json) {
  284. var _this = this;
  285. try {
  286. json = JSON.parse(json);
  287. if (json.retHead) {
  288. _this.json.code = json.retHead.errCode;
  289. _this.json.msg = json.retHead.errMsg || "不知道怎么了!!!";
  290. _this.json.count = json.retHead.total || 0;
  291. } else {
  292. }
  293. if (JSON.stringify(json.retBody) == '{}') {
  294. json.retBody = []
  295. }
  296. if (json.retBody && !!json.retBody.list && !!json.retBody.list.length) {
  297. _this.json.count = _this.json.count || json.retBody.total || 0;
  298. _this.json.data = json.retBody.list || [];
  299. _this.json.button = json.buttonRep || {};
  300. if (JSON.stringify(_this.json.button) != '{}') {
  301. (function addRgt(data, rgt) {
  302. for (let i = 0; i < data.length; i++) {
  303. data[i] = Object.assign(data[i], rgt);
  304. if (data[i].children)
  305. addRgt(data[i].children, rgt);
  306. }
  307. })(_this.json.data, _this.json.button);
  308. for (let i = 0; i < _this.json.data.length; i++) {
  309. _this.json.data[i] = Object.assign(_this.json.data[i], _this.json.button);
  310. }
  311. }
  312. } else if (json.retBody != "null" && !!json.retBody && Array.isArray(json.retBody.list) && !json.retBody.total) {
  313. _this.json.data = [];
  314. _this.json.button = json.buttonRep || {};
  315. if (JSON.stringify(_this.json.button) != '{}') {
  316. (function addRgt(data, rgt) {
  317. for (let i = 0; i < data.length; i++) {
  318. data[i] = Object.assign(data[i], rgt);
  319. if (data[i].children)
  320. addRgt(data[i].children, rgt);
  321. }
  322. })(_this.json.data, _this.json.button);
  323. for (let i = 0; i < _this.json.data.length; i++) {
  324. _this.json.data[i] = Object.assign(_this.json.data[i], _this.json.button);
  325. }
  326. }
  327. } else {
  328. _this.json.data = Array.isArray(json.retBody) ? (function () {
  329. _this.json.count = _this.json.count || json.retBody.length;
  330. return json.retBody;
  331. })() : (json.retBody != 'null' ? [json.retBody] : []);
  332. }
  333. } catch (e) {
  334. _this.json = {
  335. code: -404,
  336. msg: "返回数据格式错误",
  337. count: 0,
  338. data: []
  339. };
  340. }
  341. return this;
  342. };
  343. win.hijack.prototype.errorMsg = function (code, msg) {
  344. var _this = this;
  345. _this.layer.msg("(" + code + ") " + (msg || "服务器通讯不畅!"), {
  346. icon: 2,
  347. time: 3000
  348. });
  349. return (window.hywa.codeVerify[(code - 0 || 'default')] || window.hywa.codeVerify['default'])();
  350. };
  351. win.hijack.prototype.okMsg = function (msg) {
  352. var _this = this;
  353. _this.layer.msg(msg, {
  354. icon: 1,
  355. time: 800
  356. });
  357. return false;
  358. };
  359. win.hijack.prototype.setRequestHeader = function (xhr) {
  360. var _this = this;
  361. if (typeof xhr.RequestHeader == 'undefined') {
  362. xhr.RequestHeader = true;
  363. var token = layui.sessionData(window.hywa.sessionTable.tableName);
  364. JSON.stringify(token) != '{}' && xhr.setRequestHeader('accessToken', token.token);
  365. }
  366. };
  367. var hook = new hijack();
  368. hookAjax({
  369. //拦截函数
  370. open: function (arg) {
  371. return hook.open(arg, this.xhr);
  372. },
  373. //拦截回调
  374. onreadystatechange: function (xhr) {
  375. // console.log(xhr.readyState)
  376. return hook.onload(xhr);
  377. },
  378. onload: function (xhr) {
  379. return hook.onload(xhr);
  380. },
  381. setRequestHeader: function (h, xhr) {
  382. // console.log("加头",JSON.stringify(xhr));
  383. hook.setRequestHeader(xhr);
  384. }
  385. });
  386. })(window);
  387. /**
  388. * 时间格式化
  389. */
  390. Date.prototype.format = function (format) {
  391. var date = {
  392. "M+": this.getMonth() + 1,
  393. "d+": this.getDate(),
  394. "h+": this.getHours(),
  395. "m+": this.getMinutes(),
  396. "s+": this.getSeconds(),
  397. "q+": Math.floor((this.getMonth() + 3) / 3),
  398. "S+": this.getMilliseconds()
  399. };
  400. if (/(y+)/i.test(format)) {
  401. format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  402. }
  403. for (var k in date) {
  404. if (new RegExp("(" + k + ")").test(format)) {
  405. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
  406. date[k] : ("00" + date[k]).substr(("" + date[k]).length));
  407. }
  408. }
  409. return format;
  410. }
  411. /**
  412. * URL参数转换为对象
  413. */
  414. Location.prototype.searchObj = function (url) {
  415. var obj = {};
  416. var arr = (url || this.search).match(/[?&][^?&]+=[^?&]+/g);
  417. if (arr) {
  418. arr.forEach(function (item) {
  419. var tempArr = item.substring(1).split('=');
  420. obj[decodeURIComponent(tempArr[0])] = decodeURIComponent(tempArr[1]);
  421. length++;
  422. });
  423. }
  424. return obj;
  425. }