util.js 1.9 KB

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