angular.app.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. app.controller('AppCtrl', [ '$rootScope', '$scope', '$http', '$localStorage', '$location', '$q', '$timeout', '$sce', function($rootScope, $scope, $http, $localStorage, $location, $q, $timeout, $sce) {
  2. /***************************************************************************
  3. * Frame参数
  4. */
  5. $rootScope.frame = {
  6. CompanyName : '',
  7. FrameVersion : '2.0.0',
  8. WaitWindow : false
  9. };
  10. $rootScope.ArtStdReg = undefined;
  11. // 设置cookeis
  12. $rootScope.setLocalStorage = function(name, value) {
  13. $localStorage[name] = value;
  14. };
  15. // 获取cookies
  16. $rootScope.getLocalStorage = function(name) {
  17. return $localStorage[name];
  18. };
  19. // 内部跳转
  20. $rootScope.goLocation = function(url) {
  21. $location.path('app/' + url);
  22. };
  23. // 到首页
  24. $rootScope.goWechat = function(url) {
  25. window.location = './wechat.jsp';
  26. };
  27. $scope.closeWechat = function() {
  28. WeixinJSBridge.call('closeWindow');
  29. }
  30. $rootScope.showHtml = function(html) {
  31. var value = html.replace(/ /g, '&nbsp;').replace(/\n/g, '<br />');
  32. return $sce.trustAsHtml(value);
  33. }
  34. // Ajax统一请求函数
  35. $rootScope.ajaxRequest = function(params, fn) {
  36. if (params == undefined)
  37. params = {};
  38. if (params.data == undefined)
  39. params.data = {};
  40. if ($rootScope.ArtStdReg != undefined)
  41. params.data.std_id = $rootScope.ArtStdReg.std_id;
  42. var params = angular.extend({
  43. method : 'post'
  44. }, params);
  45. $http(params).then(function onSuccess(response) {
  46. // $.hideLoading();
  47. if (response == undefined)
  48. console.log(params);
  49. fn.call(undefined, response.data);
  50. });
  51. };
  52. // 将date转换成长时间串
  53. $rootScope.isAfterTime = function(date, now) {
  54. if (now == undefined)
  55. now = new Date();
  56. if (!angular.isDate(date))
  57. date = $rootScope.parseLongString(date);
  58. console.log(date.getTime() - now.getTime());
  59. return date.getTime() > now.getTime();
  60. };
  61. // 将date转换成长时间串
  62. $rootScope.longDateString = function(date) {
  63. if (date == undefined)
  64. date = new Date();
  65. if (angular.isDate(date))
  66. return date.toJSON();
  67. return "";
  68. };
  69. // 将date转换成长时间串
  70. $rootScope.longMinuteString = function(date) {
  71. return $rootScope.longDateString(date).substr(0, 15);
  72. };
  73. // 将日期转换成短时间串
  74. $rootScope.shortDateString = function(date) {
  75. if (date == undefined)
  76. return "";
  77. if (angular.isDate(date))
  78. date = date.toJSON();
  79. if (date.length > 10)
  80. return date.substr(0, 10);
  81. return date;
  82. };
  83. // 获取日期的时间串
  84. $rootScope.shortTimeString = function(date) {
  85. if (date == undefined)
  86. return "";
  87. if (angular.isDate(date))
  88. date = date.toJSON();
  89. if (date.length > 10)
  90. return date.substr(11, 5);
  91. return date;
  92. }
  93. // 将短日期时间串转换成日期
  94. $rootScope.parseShortString = function(date) {
  95. if (date == undefined)
  96. date = new Date();
  97. var str = $rootScope.shortDateString(date);
  98. return new Date(Date.parse(str.replace(/-/g, "/")));
  99. }
  100. // 将长时间串转化成日期
  101. $rootScope.parseLongString = function(date) {
  102. if (angular.isDate(date))
  103. return date;
  104. if (date == undefined || date.length != 19)
  105. return undefined;
  106. return new Date(Date.parse(date.replace(/-/g, "/")));
  107. }
  108. // 获取url参数
  109. $rootScope.GetQueryString = function(name) {
  110. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  111. var r = window.location.search.substr(1).match(reg);
  112. if (r != null)
  113. return unescape(r[2]);
  114. return null;
  115. };
  116. $rootScope.initWinxinApi = function() {
  117. $rootScope.ajaxRequest({
  118. url : '../enrol/wx/config.htm',
  119. data : {
  120. url : location.href.split('#')[0]
  121. }
  122. }, function(data) {
  123. var obj = angular.extend({
  124. debug : false
  125. }, data.entity, {
  126. jsApiList : [ 'checkJsApi', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem', 'translateVoice', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'onVoicePlayEnd', 'pauseVoice', 'stopVoice', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'getNetworkType', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard' ]
  127. });
  128. wx.error(function(res) {
  129. // 加载直到成功为止
  130. setTimeout(function() {
  131. $rootScope.initWinxinApi();
  132. }, 5000);
  133. return false;
  134. });
  135. wx.config(obj);
  136. wx.ready(function() {
  137. wx.hideOptionMenu();
  138. wx.hideAllNonBaseMenuItem();
  139. });
  140. });
  141. };
  142. $rootScope.getParamValue = function(paran_name, default_value) {
  143. if ($rootScope.FrameParam[paran_name] == undefined)
  144. return default_value;
  145. return $rootScope.FrameParam[paran_name];
  146. }
  147. $rootScope.checkParamValue = function(param_name, default_value, check_value) {
  148. var value = $rootScope.getParamValue(param_name, default_value);
  149. if ((value + '') == (check_value + ''))
  150. return true;
  151. return false;
  152. }
  153. $rootScope.InitStatus = false;
  154. $rootScope.loginSuccess = false;
  155. $rootScope.getUserInfo = function() {
  156. // 请求用户信息
  157. $.ajax({
  158. url : '../enrol/wx/user/info.htm',
  159. async : false,
  160. type : "POST",
  161. dataType : "json",
  162. data : {
  163. code : $rootScope.GetQueryString('code')
  164. },
  165. success : function(data) {
  166. $.hideLoading();
  167. if (data.success == false) {
  168. $.alert(data.errorMsg, function() {
  169. WeixinJSBridge.call('closeWindow');
  170. });
  171. // if(data.login == false) {
  172. // $.alert("微信加载出现问题,请退出重新进入公众号!", function() {
  173. // WeixinJSBridge.call('closeWindow');
  174. // });
  175. // return;
  176. // }else {
  177. // $.alert(data.errorMsg, function() {
  178. // WeixinJSBridge.call('closeWindow');
  179. // });
  180. // return;
  181. // }
  182. return;
  183. }
  184. // 初始化成功
  185. $rootScope.InitStatus = true;
  186. $rootScope.loginSuccess = true;
  187. // 初始化参数信息
  188. $rootScope.FrameParam = {};
  189. angular.forEach(data.map.FrameParamArray, function(param) {
  190. $rootScope.FrameParam[param.param_name] = param.param_value;
  191. });
  192. $rootScope.StdTypeArray = data.map.StdTypeArray;
  193. $rootScope.GraduateTypeArray = data.map.GraduateTypeArray;
  194. $rootScope.StdCategoryArray = data.map.StdCategoryArray;
  195. $rootScope.PoliticalTypeArray = data.map.PoliticalTypeArray;
  196. $rootScope.YmStdTypeArray = data.map.YmStdTypeArray;
  197. $rootScope.StdTypeArray.unshift({dict_text:'请选择', dict_value:null});
  198. $rootScope.GraduateTypeArray.unshift({dict_text:'请选择', dict_value:null});
  199. $rootScope.StdCategoryArray.unshift({dict_text:'请选择', dict_value:null});
  200. $rootScope.PoliticalTypeArray.unshift({dict_text:'请选择', dict_value:null});
  201. // 设置微信抬头
  202. if ($rootScope.FrameParam.EnrolTitle) {
  203. document.title = $rootScope.FrameParam.EnrolTitle;
  204. }
  205. // 判断当前考务状态
  206. if ($rootScope.FrameParam.ArtStatus == 'Config') {
  207. // 未开放报名,
  208. $rootScope.InitStatus = false;
  209. WeixinJSBridge.call('closeWindow');
  210. return;
  211. }
  212. $rootScope.ArtStdReg = data.map.StdReg;
  213. $rootScope.WxUser = data.map.WxUser;
  214. // --std_info
  215. if (data.map.StdReg != undefined) {
  216. // 处理考生信息
  217. if (data.map.StdReg.reg_status == 'IdCard') {
  218. // 上传了证件照片
  219. $rootScope.goLocation('std/reg');
  220. } else if (data.map.StdReg.reg_status == 'NoCrownPhoto') {
  221. // 上传免冠照片
  222. $rootScope.goLocation('std/reg');
  223. } else if (data.map.StdReg.std_score_file == 'firstLogin') {
  224. $rootScope.goLocation('std/info');
  225. } else {
  226. $rootScope.goLocation('main');
  227. }
  228. } else {
  229. if ($rootScope.FrameParam.AllowStdReg == 'InActive') {
  230. // 不允许考生自行注册
  231. if($rootScope.FrameParam.GeneralExam == 'Active') {
  232. $rootScope.goLocation('std/wybinding');
  233. } else {
  234. $rootScope.goLocation('std/binding');
  235. }
  236. } else {
  237. //$rootScope.goLocation('std/reg');
  238. $rootScope.goLocation('std/notice');
  239. }
  240. return;
  241. }
  242. },
  243. error : function(data) {
  244. }
  245. });
  246. }
  247. $rootScope.getJudgerInfo = function() {
  248. $.ajax({
  249. url : '../judge/wx/judger/info.htm',
  250. async : false,
  251. type : "POST",
  252. dataType : "json",
  253. data : {
  254. code : $rootScope.GetQueryString('code')
  255. },
  256. success : function(data) {
  257. $.hideLoading();
  258. if (data.success == false) {
  259. $.alert(data.errorMsg, function() {
  260. WeixinJSBridge.call('closeWindow');
  261. });
  262. return;
  263. }
  264. // 初始化成功
  265. $rootScope.InitStatus = true;
  266. $rootScope.loginSuccess = true;
  267. // 初始化参数信息
  268. $rootScope.FrameParam = {};
  269. angular.forEach(data.map.FrameParamArray, function(param) {
  270. $rootScope.FrameParam[param.param_name] = param.param_value;
  271. });
  272. $rootScope.WxUser = data.map.WxUser;
  273. if (data.map.WxUser) {
  274. $rootScope.goLocation('judge');
  275. }
  276. /*
  277. * else{ $rootScope.goLocation('judge/binding'); }
  278. */
  279. },
  280. error : function(data) {
  281. }
  282. });
  283. }
  284. $rootScope.initWinxinApi();
  285. if (location.search.indexOf('?judge') != -1) {
  286. $rootScope.getJudgerInfo();
  287. } else {
  288. $rootScope.getUserInfo();
  289. }
  290. $rootScope.isProvinceStd = function() {
  291. if ($rootScope.ArtStdReg.std_province == $rootScope.FrameParam.SchoolProvince)
  292. return true;
  293. return false;
  294. }
  295. $rootScope.getTimeName = function(time_type) {
  296. if (time_type + '' == '1')
  297. return '上午';
  298. else if (time_type + '' == '2')
  299. return '下午';
  300. if (time_type + '' == '3')
  301. return '晚上';
  302. else
  303. return time_type;
  304. }
  305. //判断是否使用手机打开微信
  306. $rootScope.isMobile = function() {
  307. if(window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
  308. return true; // 移动端
  309. } else {
  310. return false; // PC端
  311. }
  312. }
  313. $rootScope.uploadStdMaterial = function(material_type, fn, enrol_id) {
  314. if(!$rootScope.isMobile()) {
  315. $.alert('请使用手机微信操作上传!');
  316. return;
  317. }
  318. wx.chooseImage({
  319. count : 1, // 默认9
  320. sizeType : [ 'compressed' ], // 可以指定是原图还是压缩图,默认二者都有'original',
  321. sourceType : [ 'album', 'camera' ], // 可以指定来源是相册还是相机,默认二者都有
  322. success : function(res) {
  323. var localIds = res.localIds;
  324. wx.uploadImage({
  325. localId : localIds[0], // 需要上传的图片的本地ID,由chooseImage接口获得
  326. isShowProgressTips : 1, // 默认为1,显示进度提示
  327. success : function(serverRes) {
  328. var serverId = serverRes.serverId; // 返回图片的服务器端ID
  329. $.showLoading("考生材料上传中,请稍候...")
  330. // 上传成功,去服务器取图片
  331. var vData = {
  332. std_id : $rootScope.ArtStdReg.std_id,
  333. media_id : serverId,
  334. material_type : material_type
  335. };
  336. if (enrol_id)
  337. vData.enrol_id = enrol_id;
  338. $rootScope.ajaxRequest({
  339. url : '../enrol/std/material/upload.htm',
  340. method : 'post',
  341. data : vData
  342. }, function(data) {
  343. $.hideLoading();
  344. $rootScope[material_type] = data.entity;
  345. if (material_type == 'NoCrownPhoto') {
  346. $rootScope.ArtStdReg.std_image = data.entity.material_file;
  347. }
  348. if (fn)
  349. fn.call(undefined, data);
  350. });
  351. },
  352. fail : function(error) {
  353. $.alert('图片服务器暂时无法访问,请稍侯再试', '错误提示');
  354. }
  355. });
  356. }
  357. });
  358. }
  359. $rootScope.uploadStdMaterialOnline = function(material_type, fn, enrol_id) {
  360. if(!$rootScope.isMobile()) {
  361. $.alert('请使用手机微信拍照上传免冠照!');
  362. return;
  363. }
  364. wx.chooseImage({
  365. count : 1, // 默认9
  366. sizeType : [ 'compressed' ], // 可以指定是原图还是压缩图,默认二者都有'original',
  367. sourceType : [ 'camera' ], // 可以指定来源是相册还是相机,默认二者都有
  368. success : function(res) {
  369. var localIds = res.localIds;
  370. wx.uploadImage({
  371. localId : localIds[0], // 需要上传的图片的本地ID,由chooseImage接口获得
  372. isShowProgressTips : 1, // 默认为1,显示进度提示
  373. success : function(serverRes) {
  374. var serverId = serverRes.serverId; // 返回图片的服务器端ID
  375. $.showLoading("考生材料上传中,请稍候...")
  376. // 上传成功,去服务器取图片
  377. var vData = {
  378. std_id : $rootScope.ArtStdReg.std_id,
  379. media_id : serverId,
  380. material_type : material_type
  381. };
  382. if (enrol_id)
  383. vData.enrol_id = enrol_id;
  384. $rootScope.ajaxRequest({
  385. url : '../enrol/std/material/upload.htm',
  386. method : 'post',
  387. data : vData
  388. }, function(data) {
  389. $.hideLoading();
  390. $rootScope[material_type] = data.entity;
  391. if (material_type == 'NoCrownPhoto') {
  392. $rootScope.ArtStdReg.std_image = data.entity.material_file;
  393. }
  394. if (fn)
  395. fn.call(undefined, data);
  396. });
  397. },
  398. fail : function(error) {
  399. $.alert('图片服务器暂时无法访问,请稍侯再试', '错误提示');
  400. }
  401. });
  402. }
  403. });
  404. }
  405. } ]);