util.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. function lt(obj) {
  2. console.table(JSON.parse(JSON.stringify(obj)));
  3. }
  4. function deepClone(obj) {
  5. return JSON.parse(JSON.stringify(obj))
  6. }
  7. const app = {
  8. baseUrl: "http://www.tianyunperfect.cn:3000/mock/75",
  9. // baseUrl: "http://127.0.0.1:8089",
  10. };
  11. Date.prototype.format = function (fmt) {
  12. const o = {
  13. "M+": this.getMonth() + 1, //月份
  14. "d+": this.getDate(), //日
  15. "h+": this.getHours(), //小时
  16. "m+": this.getMinutes(), //分
  17. "s+": this.getSeconds(), //秒
  18. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  19. "S": this.getMilliseconds() //毫秒
  20. };
  21. if (/(y+)/.test(fmt)) {
  22. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  23. }
  24. for (const k in o) {
  25. if (new RegExp("(" + k + ")").test(fmt)) {
  26. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  27. }
  28. }
  29. return fmt;
  30. };
  31. // 添加响应拦截器
  32. axios.interceptors.response.use(function (response) {
  33. // 对响应数据做点什么
  34. return response.data;
  35. }, function (error) {
  36. // 对响应错误做点什么
  37. return Promise.reject(error);
  38. });
  39. function my_alert(string) {
  40. $("body").prepend($(`<div id="my_alert_danger" class="my_alert alert alert-danger">${string}</div>`))
  41. setTimeout(()=>{
  42. $("#my_alert_danger").remove();
  43. },2000)
  44. }
  45. function my_success(string) {
  46. $("body").prepend($(`<div id="my_alert_success" class="my_alert alert alert-success">${string}</div>`))
  47. setTimeout(()=>{
  48. $("#my_alert_success").remove();
  49. },2000)
  50. }