angular.app.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. app.controller('AppCtrl', [ '$rootScope', '$scope', '$http', '$location', '$q', '$timeout', '$sce', function($rootScope, $scope, $http, $location, $q, $timeout, $sce) {
  2. $rootScope.showHtml = function(html) {
  3. var value = html.replace(/ /g, '&nbsp;').replace(/\n/g, '<br />');
  4. return $sce.trustAsHtml(value);
  5. }
  6. // Ajax统一请求函数
  7. $rootScope.ajaxRequest = function(params, fn) {
  8. if (params == undefined)
  9. params = {};
  10. if (params.data == undefined)
  11. params.data = {};
  12. var params = angular.extend({
  13. method : 'post'
  14. }, params);
  15. //http://art.hmsoft.cn/cy/exam/judge/grade/info/loginname.htm
  16. $http(params).then(function onSuccess(response) {
  17. // $.hideLoading();
  18. if (response == undefined)
  19. console.log(params);
  20. if (fn != undefined)
  21. fn.call(undefined, response.data);
  22. });
  23. };
  24. // 将date转换成长时间串
  25. $rootScope.longDateString = function(date) {
  26. date = new Date();
  27. if (angular.isDate(date))
  28. return date.toJSON();
  29. return "";
  30. };
  31. // 将date转换成长时间串
  32. $rootScope.longMinuteString = function(date) {
  33. return $rootScope.longDateString(date).substr(0, 15);
  34. };
  35. // 将日期转换成短时间串
  36. $rootScope.shortDateString = function(date) {
  37. if (date == undefined)
  38. return "";
  39. if (angular.isDate(date))
  40. date = date.toJSON();
  41. if (date.length > 10)
  42. return date.substr(0, 10);
  43. return date;
  44. };
  45. // 获取日期的时间串
  46. $rootScope.shortTimeString = function(date) {
  47. if (date == undefined)
  48. return "";
  49. if (angular.isDate(date))
  50. date = date.toJSON();
  51. if (date.length > 10)
  52. return date.substr(11, 5);
  53. return date;
  54. }
  55. // 将短日期时间串转换成日期
  56. $rootScope.parseShortString = function(date) {
  57. if (date == undefined)
  58. date = new Date();
  59. var str = $rootScope.shortDateString(date);
  60. return new Date(Date.parse(str.replace(/-/g, "/")));
  61. }
  62. // 将长时间串转化成日期
  63. $rootScope.parseLongString = function(date) {
  64. if (angular.isDate(date))
  65. return date;
  66. if (date == undefined || date.length != 19)
  67. return undefined;
  68. return new Date(Date.parse(date.replace(/-/g, "/")));
  69. }
  70. } ]);