江夏图书馆大屏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
7.9 KiB

6 months ago
  1. <template>
  2. <div style="height: calc(100% - 200px); display: flex; align-items: center; justify-content: flex-start;">
  3. <div id="todayType" style="width:400px; height: 230px" />
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. todayAllNum: {
  10. type: Object,
  11. require: true,
  12. default: function() {
  13. return {}
  14. }
  15. }
  16. },
  17. data() {
  18. return {
  19. }
  20. },
  21. watch: {
  22. 'todayAllNum': {
  23. handler(val) {
  24. setTimeout(() => {
  25. this.initTodayCircle()
  26. }, 100)
  27. },
  28. immediate: true,
  29. deep: true
  30. }
  31. },
  32. created() {
  33. },
  34. beforeDestroy() {
  35. },
  36. mounted() {
  37. this.initTodayCircle()
  38. },
  39. methods: {
  40. initTodayCircle() {
  41. const optionData = [
  42. { value: this.todayAllNum.headerLib || 0, name: '总馆' }
  43. // { value: this.todayAllNum.branchLib || 0, name: '分馆' }
  44. ]
  45. const myChart = this.$echarts.init(document.getElementById('todayType'))
  46. function arrCount(arr) {
  47. let count = 0
  48. arr.forEach(item => {
  49. count = count + item.value
  50. })
  51. return count
  52. }
  53. var centerImg = require('@/assets/images/circle-bg.png')
  54. const option = {
  55. baseOption: {
  56. tooltip: {
  57. show: false,
  58. trigger: 'item',
  59. position: 'bottom',
  60. textStyle: {
  61. color: '#EEF6FF',
  62. fontSize: '18'
  63. }
  64. // backgroundColor: 'rgba(74, 144, 226, 0.84)',
  65. // formatter: (params) => {
  66. // return `<div>${params.seriesName} <br> ${params.data.name}:${this.$parent.formatter(params.data.value)} (${params.percent}%)</div>`
  67. // }
  68. },
  69. legend: {
  70. orient: 'vertical',
  71. right: 70,
  72. top: 125,
  73. // textStyle: {
  74. // color: '#EEF6FF',
  75. // padding: [20, 0, 18, 4],
  76. // fontSize: '14'
  77. // },
  78. itemWidth: 10,
  79. itemHeight: 10,
  80. icon: 'circle',
  81. selectedMode: false,
  82. data: ['总馆'],
  83. formatter: (name) => {
  84. // `${name} ${((flag.value / count).toFixed(2)) * 100 + '%'}`
  85. const count = arrCount(optionData)
  86. if (optionData) {
  87. const flag = optionData?.find(item => name === item.name)
  88. if (flag) {
  89. const percentage = count > 0 ? ((flag.value / count) * 100).toFixed(0) + '%' : '0%'
  90. return [`{name|${name}}`, `{num|${percentage}}`]
  91. }
  92. }
  93. return name
  94. },
  95. textStyle: {
  96. rich: {
  97. name: {
  98. fontSize: 18,
  99. color: '#EEF6FF',
  100. padding: [20, 0, 20, 4],
  101. fontFamily: 'DingTalk_JinBuTi_Regular'
  102. },
  103. num: {
  104. fontSize: 20,
  105. fontWeight: 600,
  106. padding: [20, 0, 20, 15],
  107. color: '#4C90FF',
  108. fontFamily: 'DingTalk_JinBuTi_Regular'
  109. }
  110. }
  111. }
  112. },
  113. // 中心图片配置(关键代码)
  114. graphic: [
  115. {
  116. type: 'image',
  117. id: 'logo',
  118. left: '8.5%', // 调整图片位置
  119. top: '22%', // 调整图片位置
  120. z: -10,
  121. bounding: 'raw',
  122. rotation: 0, // 旋转
  123. origin: [64.5, 32.5], // 中心点
  124. scale: [1.0, 1.0], // 缩放
  125. // 设置图片样式
  126. style: {
  127. image: centerImg,
  128. width: 132,
  129. height: 131,
  130. opacity: 1
  131. }
  132. }
  133. ],
  134. series: [
  135. {
  136. name: '今日累计借阅',
  137. type: 'pie',
  138. left: '-50%',
  139. radius: ['60%', '70%'],
  140. avoidLabelOverlap: false,
  141. label: {
  142. show: false,
  143. position: 'center'
  144. },
  145. labelLine: {
  146. show: true
  147. },
  148. itemStyle: {
  149. borderWidth: 2,
  150. borderColor: 'rgba(16,16,21,0.4)'
  151. },
  152. emphasis: {
  153. label: {
  154. show: true,
  155. // 自定义文字显示,函数默认params接受当前指向所有属性
  156. formatter: function(params) {
  157. const { value, name } = params
  158. return [
  159. `{c| ${value}}`,
  160. `{b| ${name}}`
  161. ].join('\n') // 换行
  162. },
  163. rich: {
  164. c: {
  165. fontSize: 24,
  166. fontWeight: 600,
  167. color: '#317FFF',
  168. fontFamily: 'DingTalk_JinBuTi_Regular',
  169. lineHeight: 34
  170. },
  171. b: {
  172. fontSize: 18,
  173. color: '#fff',
  174. fontFamily: 'DingTalk_JinBuTi_Regular'
  175. }
  176. }
  177. }
  178. },
  179. color: ['#317FFF'],
  180. data: optionData
  181. }
  182. ]
  183. },
  184. media: [
  185. {
  186. query: {
  187. maxWidth: 317
  188. },
  189. option: {
  190. legend: {
  191. right: 30,
  192. top: 'center',
  193. textStyle: {
  194. rich: {
  195. name: {
  196. fontSize: 14
  197. },
  198. num: {
  199. fontSize: 16
  200. }
  201. }
  202. }
  203. },
  204. // 中心图片配置(关键代码)
  205. graphic: [
  206. {
  207. left: '8%', // 调整图片位置
  208. top: '26%', // 调整图片位置
  209. z: -10,
  210. bounding: 'raw',
  211. rotation: 0, // 旋转
  212. origin: [64.5, 32.5], // 中心点
  213. scale: [1.0, 1.0], // 缩放
  214. // 设置图片样式
  215. style: {
  216. image: centerImg,
  217. width: 110,
  218. height: 110,
  219. opacity: 1
  220. }
  221. }
  222. ],
  223. series: [
  224. {
  225. type: 'pie',
  226. radius: ['50%', '55%'],
  227. emphasis: {
  228. label: {
  229. rich: {
  230. c: {
  231. fontSize: 22,
  232. lineHeight: 28
  233. },
  234. b: {
  235. fontSize: 16
  236. }
  237. }
  238. }
  239. }
  240. }
  241. ]
  242. }
  243. }
  244. ]
  245. }
  246. myChart.setOption(option)
  247. // // 然后可以通过定时器来旋转背景图
  248. // var step = 0
  249. // setInterval(function() {
  250. // // 每秒旋转1度
  251. // myChart.setOption({
  252. // graphic: {
  253. // id: 'logo',
  254. // style: {
  255. // transform: 'rotate(' + (step++ % 360) + 'deg)' // 持续旋转
  256. // }
  257. // }
  258. // })
  259. // }, 1000)
  260. this.$LoopShowTooltip(myChart, option.baseOption, { loopSeries: true, interval: 4000 })
  261. }
  262. }
  263. }
  264. </script>
  265. <style lang="scss">
  266. @import "~@/assets/styles/index.scss";
  267. @import "~@/assets/styles/font-some.css";
  268. </style>