祁阳图书馆智慧大屏
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.

285 lines
8.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. <template>
  2. <div style="height: calc(100% - 200px); display: flex; align-items: center; justify-content: flex-start;">
  3. <div id="modelType" style="width:400px; height: 230px" />
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. yearAllNum: {
  10. type: Object,
  11. require: true,
  12. default: function() {
  13. return {}
  14. }
  15. }
  16. },
  17. data() {
  18. return {
  19. }
  20. },
  21. watch: {
  22. 'yearAllNum': {
  23. handler(val) {
  24. setTimeout(() => {
  25. this.initYearCircle()
  26. }, 100)
  27. },
  28. immediate: true,
  29. deep: true
  30. }
  31. },
  32. created() {
  33. },
  34. beforeDestroy() {
  35. },
  36. mounted() {
  37. this.initYearCircle()
  38. },
  39. methods: {
  40. initYearCircle() {
  41. const optionData = [
  42. { value: this.yearAllNum.headerLib || 0, name: '总馆' },
  43. { value: this.yearAllNum.branchLib || 0, name: '分馆' }
  44. ]
  45. const myChart = this.$echarts.init(document.getElementById('modelType'))
  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: 55,
  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) return [`{name|${name}}`, `{num|${((flag.value / count).toFixed(2)) * 100 + '%'}}`]
  89. } else return name
  90. },
  91. textStyle: {
  92. rich: {
  93. name: {
  94. fontSize: 18,
  95. color: '#EEF6FF',
  96. fontFamily: 'DingTalk_JinBuTi_Regular',
  97. padding: [20, 0, 20, 4]
  98. },
  99. num: {
  100. fontSize: 20,
  101. fontWeight: 600,
  102. padding: [20, 0, 20, 15],
  103. color: '#4C90FF',
  104. fontFamily: 'DingTalk_JinBuTi_Regular'
  105. }
  106. }
  107. }
  108. // formatter: function(name) {
  109. // let tarValue
  110. // const count = arrCount(optionData)
  111. // for (let i = 0; i < optionData.length; i++) {
  112. // if (data[i].name === name) {
  113. // tarValue = data[i].value
  114. // }
  115. // }
  116. // return [`{name|${name}}`, `{num|${((tarValue / count).toFixed(2)) * 100 + '%'}}`].join('\n')
  117. // }
  118. },
  119. // 中心图片配置(关键代码)
  120. graphic: [
  121. {
  122. type: 'image',
  123. id: 'logo',
  124. left: '8.5%', // 调整图片位置
  125. top: '22%', // 调整图片位置
  126. z: -10,
  127. bounding: 'raw',
  128. rotation: 0, // 旋转
  129. origin: [64.5, 32.5], // 中心点
  130. scale: [1.0, 1.0], // 缩放
  131. // 设置图片样式
  132. style: {
  133. image: centerImg,
  134. width: 132,
  135. height: 131,
  136. opacity: 1
  137. }
  138. }
  139. ],
  140. series: [
  141. {
  142. name: '本年累计借阅',
  143. type: 'pie',
  144. left: '-50%',
  145. radius: ['60%', '70%'],
  146. avoidLabelOverlap: false,
  147. label: {
  148. show: false,
  149. position: 'center'
  150. },
  151. labelLine: {
  152. show: true
  153. },
  154. itemStyle: {
  155. borderWidth: 2,
  156. borderColor: 'rgba(16,16,21,0.4)'
  157. },
  158. emphasis: {
  159. label: {
  160. show: true,
  161. // 自定义文字显示,函数默认params接受当前指向所有属性
  162. formatter: function(params) {
  163. const { value, name } = params
  164. return [
  165. `{c| ${value}}`,
  166. `{b| ${name}}`
  167. ].join('\n') // 换行
  168. },
  169. rich: {
  170. c: {
  171. fontSize: 24,
  172. fontWeight: 600,
  173. color: '#317FFF',
  174. fontFamily: 'DingTalk_JinBuTi_Regular',
  175. // color: {
  176. // type: 'linear',
  177. // x: 0,
  178. // y: 0,
  179. // x2: 0,
  180. // y2: 1,
  181. // colorStops: [
  182. // {
  183. // offset: 0,
  184. // color: 'red' // 0% 处的颜色
  185. // },
  186. // {
  187. // offset: 1,
  188. // color: 'yellow' // 100% 处的颜色
  189. // }
  190. // ],
  191. // globalCoord: false // 缺省为 false
  192. // },
  193. lineHeight: 34
  194. },
  195. b: {
  196. fontSize: 18,
  197. color: '#fff',
  198. fontFamily: 'DingTalk_JinBuTi_Regular'
  199. }
  200. }
  201. }
  202. },
  203. color: ['#317FFF', '#31DFFF'],
  204. data: optionData
  205. }
  206. ]
  207. },
  208. media: [
  209. {
  210. query: {
  211. maxWidth: 317
  212. },
  213. option: {
  214. legend: {
  215. right: 30,
  216. top: 'center',
  217. textStyle: {
  218. rich: {
  219. name: {
  220. fontSize: 14
  221. },
  222. num: {
  223. fontSize: 16
  224. }
  225. }
  226. }
  227. },
  228. // 中心图片配置(关键代码)
  229. graphic: [
  230. {
  231. left: '8%', // 调整图片位置
  232. top: '26%', // 调整图片位置
  233. z: -10,
  234. bounding: 'raw',
  235. rotation: 0, // 旋转
  236. origin: [64.5, 32.5], // 中心点
  237. scale: [1.0, 1.0], // 缩放
  238. // 设置图片样式
  239. style: {
  240. image: centerImg,
  241. width: 110,
  242. height: 110,
  243. opacity: 1
  244. }
  245. }
  246. ],
  247. series: [
  248. {
  249. type: 'pie',
  250. radius: ['50%', '55%'],
  251. emphasis: {
  252. label: {
  253. rich: {
  254. c: {
  255. fontSize: 22,
  256. lineHeight: 28
  257. },
  258. b: {
  259. fontSize: 16
  260. }
  261. }
  262. }
  263. }
  264. }
  265. ]
  266. }
  267. }
  268. ]
  269. }
  270. myChart.setOption(option)
  271. this.$LoopShowTooltip(myChart, option.baseOption, { loopSeries: true, interval: 4000 })
  272. }
  273. }
  274. }
  275. </script>
  276. <style lang="scss">
  277. @import "~@/assets/styles/index.scss";
  278. @import "~@/assets/styles/font-some.css";
  279. </style>