utils.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import {
  2. ElMessage
  3. } from 'element-plus'
  4. import {
  5. ElMessageBox
  6. } from 'element-plus'
  7. export default {
  8. name: "utils",
  9. /**
  10. * 保存界面配置参数
  11. * @param {Object} config
  12. */
  13. saveConfig: function(config) {
  14. localStorage.setItem("config", JSON.stringify(config));
  15. },
  16. showerror: function(msg) {
  17. ElMessage.error(msg);
  18. },
  19. showconfirm: function(msg) {
  20. ElMessageBox.confirm(
  21. msg,
  22. '提示', {
  23. confirmButtonText: '确定',
  24. cancelButtonText: '取消',
  25. type: 'warning',
  26. }
  27. )
  28. .then(() => {
  29. ElMessage({
  30. type: 'success',
  31. message: '退出成功',
  32. })
  33. })
  34. .catch(() => {})
  35. },
  36. /**
  37. * 创建图表标题
  38. * @param {Object} title
  39. */
  40. createChartTitle: function(title) {
  41. return {
  42. text: title,
  43. textStyle: {
  44. color: "#fff",
  45. fontWeight: 'normal'
  46. },
  47. x: 'center',
  48. y: '10'
  49. }
  50. },
  51. /**
  52. * 创建图表背景
  53. * @param {Object} title
  54. */
  55. createChartGaid: function(left, right, top, bottom) {
  56. return {
  57. left: left ? left : '30',
  58. right: right ? right : '10',
  59. top: top ? top : '50px',
  60. bottom: bottom ? bottom : '40'
  61. }
  62. },
  63. /**
  64. * 创建图表背景
  65. * @param {Object} title
  66. */
  67. createChartBaseOption: function(title, left, right, top, bottom, categorys) {
  68. return {
  69. title: this.createChartTitle(title),
  70. tooltip: {
  71. show: true,
  72. trigger: 'axis'
  73. },
  74. grid: this.createChartGaid(left, right, top, bottom),
  75. xAxis: {
  76. type: 'category',
  77. axisLine: {
  78. show: true,
  79. lineStyle: {
  80. color: this.getChartXColor()
  81. }
  82. },
  83. axisLabel: {
  84. color: this.getChartXTextColor()
  85. },
  86. axisTick: {
  87. show: false
  88. },
  89. splitLine: {
  90. show: false
  91. },
  92. boundaryGap: false,
  93. data: categorys
  94. },
  95. yAxis: {
  96. type: 'value',
  97. axisLabel: {
  98. color: this.getChartYTextColor(),
  99. },
  100. axisLine: {
  101. show: true,
  102. lineStyle: {
  103. color: this.getChartXColor()
  104. }
  105. },
  106. splitLine: {
  107. lineStyle: {
  108. color: this.getChartYColor(),
  109. type: 'dashed'
  110. },
  111. }
  112. }
  113. }
  114. },
  115. /**
  116. * 获取x轴颜色
  117. * @param {Object} title
  118. */
  119. getChartXColor: function() {
  120. // return '#85C1D9'
  121. return '#00FAC166'
  122. },
  123. /**
  124. * 获取x轴文本颜色
  125. * @param {Object} title
  126. */
  127. getChartXTextColor: function() {
  128. // return '#8BC4F2'
  129. // return '#F56C6Cbb'
  130. return '#ffffffdd'
  131. },
  132. /**
  133. * 获取y轴颜色
  134. * @param {Object} title
  135. */
  136. getChartYColor: function() {
  137. // return '#355C84'
  138. return '#00FAC166'
  139. },
  140. /**
  141. * 获取y轴文本颜色
  142. * @param {Object} title
  143. */
  144. getChartYTextColor: function() {
  145. // return '#8BC4F2'
  146. // return '#F56C6Cbb'
  147. return '#ffffffdd'
  148. }
  149. }
  150. Date.prototype.format = function(fmt) {
  151. var o = {
  152. "M+": this.getMonth() + 1, //月份
  153. "d+": this.getDate(), //日
  154. "h+": this.getHours(), //小时
  155. "m+": this.getMinutes(), //分
  156. "s+": this.getSeconds(), //秒
  157. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  158. "S": this.getMilliseconds() //毫秒
  159. };
  160. if (/(y+)/.test(fmt)) {
  161. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  162. }
  163. for (var k in o) {
  164. if (new RegExp("(" + k + ")").test(fmt)) {
  165. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k])
  166. .length)));
  167. }
  168. }
  169. return fmt;
  170. }