|
|
<template> <div style="padding: 0 .4rem;"> <div class="pageOne-database" style="height: 6.25rem !important; "> <!-- 到馆统计 --> <div class="database-left"> <h3 class="database-title">到馆统计</h3> <ul class="inLib-num"> <!-- , {'lastYearTotal': item.id === 'lastYearTotal'} --> <li v-for="item in leftData" :key="item.timestamp" :class="[{'totayTotal': item.id === 'totayTotal'}]" > <div class="pageLeft-flop-box"> <div> <span v-for="(ls, i) in item.valueArr" :key="item.id + i" :class="[{'flop-figure': !isNaN(ls)}, {'flop-comma': isNaN(ls)}]"> <i v-if="!isNaN(ls)">0123456789</i> <span v-else>{{ ls }}</span> </span> <em>人</em> </div> </div> <div class="flop-item-name">{{ item.name }}</div> </li> </ul> <ul class="pageOne-left-progress"> <li v-for="(item,index) in progressData" :key="index" :class="[{'blue-progress':item.type===1 || item.type === 2},{'orange-progress':item.type===3 || item.type === 4}]"> <p>{{ item.name }}</p> <span class="progress-num">{{ item.value }}<i>人</i></span> <el-progress :percentage="computedPercentage(item)" :stroke-width="8" :show-text="false" /> </li> </ul> </div> <div class="database-middle"> <div class="middle-img"> <div class="middle-img-book" /> <div class="wq" /> <!-- <div class="line-box"> <div class="box"> <div class="ball" /> </div> </div> --> <div class="middle-img-bottom"> <!-- width: 360px; height: 200px; margin: 50px 0 0 30px; --> <div style="position: relative; margin: 50px 0 0 20px;"> <svg width="360" height="200"> <path d="M0 80 S 170 160, 400 70" /> </svg> <div class="rect qxRect" /> </div> </div> <div class="middle-img-dot" /> </div> <div v-for="(item,index) in middleData" :key="index" :class="['middle2-item', {'totalBook': item.id === 'totalBook'}, {'fansNum': item.id === 'fansNum'}, {'lendingNum': item.id === 'lendingNum'}, {'cardNum': item.id === 'cardNum'}]"> <p>{{ item.name }}</p> <div class="middle-num"> <div class="small-module"> <div class="chartNum"> <div class="box-items"> <li v-for="(e,i) in item.valueArr" :key="i" :class="!isNaN(e) ? 'number-item':'number-item num-dot'"> <span v-if="!isNaN(e)" class="items-int"><i ref="numberItem" class="item">0123456789</i></span> <span v-else>{{ e }}</span> <!-- <span><i ref="numberItem" class="item">0123456789</i></span> --> </li> </div> </div> </div> <span v-if="item.id === 'totalBook'" class="middle-unit">册</span> <span v-if="item.id === 'fansNum'" class="middle-unit">册</span> <span v-if="item.id === 'cardNum'" class="middle-unit">个</span> <span v-if="item.id === 'lendingNum'" class="middle-unit">册</span> </div> </div> </div> <!-- 热门搜索 --> <div class="database-right"> <h3 class="database-title">热门搜索</h3> <div class="tagcloud-main"> <div v-if="tagList.length !== 0" id="tagscloud" ref="tagcloudall" class="tagscloud"> <!-- <a v-for="(item,index) in hotTagData" :key="index" :class="'tagc' + ((index % 4) + 1)"> {{ item }} </a> --> <a v-for="(item,index) in tagList" :key="index" :class="'tagc' + ((index % 4) + 1)">{{ item }}</a> </div> </div> </div> </div> <!-- 底部 图书推荐 --> <div class="pageOne-book" style="margin-top: .13rem !important;"> <!-- <h3 class="database-title">图书推荐</h3> --> <div class="pageOne-book-content" style="padding: .2rem 0 !important;"> <div class="scrollBox"> <vue-seamless-scroll ref="listData" :data="listData1" :class-option="defaultOption" class="seamless01" > <ul> <li v-for="(item, index) in listData1" :key="index"> <div class="bord"> <div class="book-img"> <img :src="item.nbImgPath" :onerror="defaultImg"> </div> </div> </li> </ul> </vue-seamless-scroll> <vue-seamless-scroll ref="listData2" :data="listData2" :class-option="default2Option" class="seamless02" > <ul> <li v-for="(item, index) in listData2" :key="index"> <div class="bord"> <div class="book-img"> <img :src="item.nbImgPath" :onerror="defaultImg"> </div> </div> </li> </ul> </vue-seamless-scroll> </div> <div style=" writing-mode: vertical-rl; padding: 0 .38rem 0 .5rem; font-size: .5rem; letter-spacing: 8px;">热门图书推荐</div> <!-- <div class="wechat-code"> <div class="wechat-img"> <img :src="wecharQrCodeSrc"> </div> <span>微信扫一扫关注</span> </div> --> </div> </div> </div></template>
<script>// FetchFansCount
// FetchLibBookTotal 暂时隐藏,因为馆藏量暂时写死
import { FetchInitSetting, FetchInitIntoNum, FetchUsertotal, FetchHotSearch, FetchLendingTotal, FetchNewBook, FetchMarcByISBN } from '@/api/library'export default { name: 'PageOne', data() { return { intervalLeft: null, isDataLoaded: false, pageOneVisitBase: '0', // 本年到馆基础数
wecharQrCodeSrc: null, newList: [], listData1: [], listData2: [], defaultImg: 'this.src="' + require('@/assets/images/book_03.png') + '"', leftData: [], progressData: [], hotTagData: [], middleData: [], tagList: [], // 热门搜索的
radius: 160, dtr: Math.PI / 180, d: 200, mcList: [], active: false, lasta: 1, lastb: 1, distr: true, tspeed: 4, size: 200, mouseX: 0, mouseY: 20, howElliptical: 1, oList: null, oA: null, sa: 0, ca: 0, sb: 0, cb: 0, sc: 0, cc: 0 } }, computed: { defaultOption() { return { step: 0.5, // 数值越大速度滚动越快
limitMoveNum: 4, // 开始无缝滚动的数据量 this.dataList.length
hoverStop: true, // 是否开启鼠标悬停stop
direction: 2, // 0向下 1向上 2向左 3向右
openWatch: true, // 开启数据实时监控刷新dom
singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
waitTime: 1000 // 单步运动停止的时间(默认值1000ms)
} }, default2Option() { return { step: 0.5, // 数值越大速度滚动越快
limitMoveNum: 4, // 开始无缝滚动的数据量 this.dataList.length
hoverStop: true, // 是否开启鼠标悬停stop
direction: 3, // 0向下 1向上 2向左 3向右
openWatch: true, // 开启数据实时监控刷新dom
singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
waitTime: 1000 // 单步运动停止的时间(默认值1000ms)
} }, computedPercentage() { return (item) => { if (item.type === 1) { return item.value > this.getType3Value() ? 100 : 70 } else if (item.type === 2) { return item.value > this.getType4Value() ? 100 : 70 } else if (item.type === 3) { return item.value > this.getType1Value() ? 100 : 70 } else if (item.type === 4) { return item.value > this.getType2Value() ? 100 : 70 } } } }, async created() { if (localStorage.getItem('yesterdayCountCache')) { localStorage.removeItem('yesterdayCountCache') } if (localStorage.getItem('lastMonthCountCache')) { localStorage.removeItem('lastMonthCountCache') } // this.getInitData()
// this.getMiddleAllData()
this.getHotSearch() this.getNewBook() }, beforeDestroy() { clearInterval(this.intervalLeft) this.intervalLeft = null }, activated() { this.pageOneVisitBase = 0 this.getInitData() this.getMiddleAllData() }, deactivated() { clearInterval(this.intervalLeft) this.intervalLeft = null }, mounted() { // this.getTest()
if (localStorage.getItem('wecharQrCodeSrc')) { this.wecharQrCodeSrc = localStorage.getItem('wecharQrCodeSrc') } }, methods: { // getTest() {
// const resData = {
// 'errCode': 0,
// 'errMsg': 'ok',
// 'data': '{"success":true,"resultlist":[{"JCC_YEAR":0,"HRC_MONTH":0,"HCC_MONTH":0,"HCC":11,"JCC":0,"JRC_DAY":0,"JRC_YEAR":0,"HRC_YEAR":1,"BZL_MONTH":0,"JRC_MONTH":0,"HCC_DAY":0,"BZL":2,"HRC":1,"JCC_DAY":0,"JRC":0,"BZL_YEAR":1,"HCC_YEAR":11,"BZL_DAY":0,"HRC_DAY":0,"JCC_MONTH":0,"LIBCODE":"999"},{"JCC_YEAR":21822,"HRC_MONTH":296,"HCC_MONTH":770,"HCC":98972,"JCC":123736,"JRC_DAY":2,"JRC_YEAR":2837,"HRC_YEAR":2167,"BZL_MONTH":158,"JRC_MONTH":409,"HCC_DAY":0,"BZL":9814,"HRC":30813,"JCC_DAY":3,"JRC":39642,"BZL_YEAR":929,"HCC_YEAR":20298,"BZL_DAY":0,"HRC_DAY":0,"JCC_MONTH":1085,"LIBCODE":"GD"},{"JCC_YEAR":195,"HRC_MONTH":25,"HCC_MONTH":46,"HCC":106,"JCC":195,"JRC_DAY":1,"JRC_YEAR":102,"HRC_YEAR":62,"BZL_MONTH":0,"JRC_MONTH":38,"HCC_DAY":77,"BZL":2,"HRC":62,"JCC_DAY":9,"JRC":102,"BZL_YEAR":2,"HCC_YEAR":106,"BZL_DAY":0,"HRC_DAY":1,"JCC_MONTH":81,"LIBCODE":"DWSF"},{"JCC_YEAR":92,"HRC_MONTH":12,"HCC_MONTH":18,"HCC":65,"JCC":92,"JRC_DAY":0,"JRC_YEAR":46,"HRC_YEAR":36,"BZL_MONTH":0,"JRC_MONTH":19,"HCC_DAY":0,"BZL":0,"HRC":36,"JCC_DAY":0,"JRC":46,"BZL_YEAR":0,"HCC_YEAR":65,"BZL_DAY":0,"HRC_DAY":0,"JCC_MONTH":37,"LIBCODE":"ZJWSF"}]}'
// }
// const result = JSON.parse(resData.data)
// console.log('【解析后的完整结果】', result)
// if (result.success & result.resultlist.length !== 0) {
// const filterData = result.resultlist.filter(item => item.LIBCODE === 'DWSF')
// console.log('【过滤出 DWSF 的数据】', filterData)
// // 4. 累加 JCC_DAY 并打印累加过程 借
// const total = filterData.reduce((acc, obj) => {
// console.log(`【累加过程】当前累计值:${acc} + 当前项 JCC_DAY:${obj.JCC_DAY} = ${acc + obj.JCC_DAY}`)
// return acc + obj.JCC_DAY
// }, 0)
// // 还
// const totalH = filterData.reduce((acc, obj) => {
// console.log(`【累加过程】当前累计值:${acc} + 当前项 JCC_DAY:${obj.HCC_DAY} = ${acc + obj.HCC_DAY}`)
// return acc + obj.HCC_DAY
// }, 0)
// // 5. 打印最终结果
// console.log('借', total)
// console.log('还', totalH)
// return total
// } else {
// console.log('【执行结果】数据获取失败或无结果,返回 0')
// return 0
// }
// },
getInitData() { // visitBase 本年到馆基础数
// wecharQrCode 二维码 用/downloadFile/+wecharQrCode
// iNotice 公告
const linkSrc = process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API console.log('linkSrc', linkSrc) FetchInitSetting().then(res => { const result = JSON.parse(res.data) this.pageOneVisitBase = result.visitBase this.wecharQrCodeSrc = linkSrc + '/downloadFile' + result.wecharQrCode // this.initLeftPreview(result)
this.initIntoNum() }) }, initIntoNum() { // 初始化数据,使用更语义化的变量名
this.progressData = [] this.leftData = []
FetchInitIntoNum() .then(res => { const result = res?.data || {} const progressDataConfig = [ // { name: '今日出馆', key: 'dayOutNUm', type: 3 },
{ name: '本月到馆', key: 'monthPeopleNum', type: 3 }, { name: '本年到馆', key: 'historyPeopleNum', type: 1 } ]
this.progressData = progressDataConfig.map(item => ({ name: item.name, value: result[item.key] || 0, type: item.type }))
// 处理今日到馆数据,抽离变量提高可读性
const dayPeopleNum = result.dayPeopleNum || 0 const formattedNum = this.$parent.formatter(dayPeopleNum)
const newData = [{ id: 'totayTotal', name: '今日到馆', value: formattedNum, valueArr: formattedNum.split(''), timestamp: Date.now() }]
// 更新数据
this.$set(this, 'leftData', newData) this.$parent.timedRefresh(this.leftData, 'left') }) .catch(error => { console.error('获取入馆数据失败:', error) }) }, initLeftPreview(result) { this.progressData = [] this.leftData = []
// visitBase 本年累计人次
// visitBaseCheck 是否直接显示 0false 1true
// lastYearVisitBase 去年累计人次
// todayVisitBase 今日人次
// todayVisitBaseCheck 是否显示
// yesterdayVisitBase 昨天人次
// yesterdayVisitBaseCheck 是否显示
// thisMonthVisitBase 本月人次
// thisMonthVisitBaseCheck 是否显示
// lastMonthVisitBase 上个月人次
// lastMonthVisitBaseCheck 是否显示
const baseTotal = this.pageOneVisitBase // 本年到馆人数
console.log('假设本年到馆人数', baseTotal) // 本年到馆/12个月 = 月基数
const monthBase = Math.floor(baseTotal / 12) // 月基数
console.log('月基数', monthBase) // 月随机数(-100到200之间)
const randomMonth = Math.floor(Math.random() * (200 - (-100) + 1)) + (-100)
const now = new Date() const year = now.getFullYear() // 当前年份
const month = now.getMonth() + 1 // 当前月份
const daysInMonth = new Date(year, month, 0).getDate() // 当月天数
console.log('当月天数', daysInMonth) // 月基数/当月天数(28、29、30、31)= 日基数
const dayBase = Math.floor(monthBase / daysInMonth) // 日基数
console.log('日基数', dayBase) // 本年累计=月基数*月份+月随机数(-100到200之间)
let nowYearCount if (result.visitBaseCheck === '1') { nowYearCount = result.visitBase } else { nowYearCount = Math.floor(monthBase * month + randomMonth) // 本年累计
} console.log('本年累计', nowYearCount) // 昨日到馆=日基数+日随机数(-20到50之间)
let yesterdayCount = 0 if (result.yesterdayVisitBaseCheck === '1') { yesterdayCount = result.yesterdayVisitBase } else { const randomDay = Math.floor(Math.random() * (50 - (-20) + 1)) + (-20) // 日随机数(-20到50之间)
// yesterdayCount = localStorage.getItem('yesterdayCountCache') ? localStorage.getItem('yesterdayCountCache') : dayBase + randomDay // 昨日到馆
yesterdayCount = dayBase + randomDay // 昨日到馆
} console.log('昨日到馆', yesterdayCount) // 上月到馆=月基数+月随机数(-100到200之间)
let lastMonthCount = 0 if (result.lastMonthVisitBaseCheck === '1') { lastMonthCount = result.lastMonthVisitBase } else { // lastMonthCount = localStorage.getItem('lastMonthCountCache') ? localStorage.getItem('lastMonthCountCache') : monthBase + randomMonth
lastMonthCount = monthBase + randomMonth } console.log('上月到馆', lastMonthCount)
// 日基数/10小时=小时基数
const hourBase = Math.floor(dayBase / 10) // 小时基数
console.log('小时基数', hourBase) // 图书馆营业时间(8:00-18:00共10小时)
// 8:00-9:00 算第1个小时、9:00-10:00算第2个小时、以此类推
const openTime = 8 // 开门时间
const closeTime = 18 // 结束时间
const currentHour = now.getHours() // 当前时间点
// 今日到馆=小时基数 * 第N小时+小时随机数(-5到10之间)
let todayCount = 0 if (result.todayVisitBaseCheck === '1') { todayCount = result.todayVisitBase } else { if (currentHour < openTime || currentHour >= closeTime) { console.log('当前时间不在图书馆营业时间内') todayCount = 0 } else { const N = currentHour - openTime // console.log('第N个小时', N)
const randomHour = Math.floor(Math.random() * (10 - (-5) + 1)) + (-5) // 小时随机数(-5到10之间)
todayCount = Math.floor(hourBase * N + randomHour) // 今日到馆
} } console.log('今日到馆', todayCount) // 本月到馆=月基数 * (当前月的日期dd/当前月的天数)+ 月随机数(-100到200之间)
let nowMonthCount = 0 if (result.thisMonthVisitBaseCheck === '1') { nowMonthCount = result.thisMonthVisitBase } else { if (now.getDate() === 1) { nowMonthCount = todayCount } else { nowMonthCount = Math.floor(monthBase * (now.getDate() / daysInMonth) + randomMonth) // 本月到馆
} } console.log('本月到馆', nowMonthCount)
this.progressData.push( // {
// name: '今日到馆',
// value: result.todayVisitBase,
// type: 1
// },
{ name: '本年到馆', value: result.visitBase, type: 1 }, { name: '本月到馆', value: result.thisMonthVisitBase, type: 2 }, // {
// name: '昨日到馆',
// value: result.yesterdayVisitBase,
// type: 3
// },
{ name: '去年到馆', value: result.lastYearVisitBase, type: 3 }, { name: '上月到馆', value: result.lastMonthVisitBase, type: 4 } )
// this.leftData.push(
// {
// // name: '今日到馆',
// // value: result.todayVisitBase,
// // type: 1
// id: 'totayTotal',
// name: '今日到馆',
// value: this.$parent.formatter(result.todayVisitBase),
// valueArr: this.$parent.formatter(result.todayVisitBase)
// }
// // {
// // id: 'allTotal',
// // name: '本年累计到馆',
// // value: this.$parent.formatter(result.visitBase),
// // valueArr: this.$parent.formatter(result.visitBase).split('')
// // },
// // {
// // id: 'lastYearTotal',
// // name: '去年累计到馆',
// // value: this.$parent.formatter(result.lastYearVisitBase),
// // valueArr: this.$parent.formatter(result.lastYearVisitBase).split('')
// // }
// )
// 更新数据
const newData = [{ id: 'totayTotal', name: '今日到馆', value: this.$parent.formatter(result.todayVisitBase), valueArr: this.$parent.formatter(result.todayVisitBase).split(''), timestamp: Date.now() }]
this.$set(this, 'leftData', newData)
this.$parent.timedRefresh(this.leftData, 'left')
// 昨日到馆、上月到馆存一个缓存!当前第一次计算好之后就不变了!
// localStorage.setItem('yesterdayCountCache', yesterdayCount)
// localStorage.setItem('lastMonthCountCache', lastMonthCount)
},
// 热门搜索
getHotSearch() { const params = { 'size': 40 } FetchHotSearch(params).then(res => { // this.hotTagData = res.data.replace(/^\[|\]$/g, '').split(', ')
this.hotTagData = ['儒林外史', '七色花', '灰尘的旅行', '余华', '伍美珍', '石刻', '龙族', '骆驼祥子', '克雷洛夫寓言', '东野圭吾', '郁雨君', '汤姆索亚历险记', '中国古代寓言故事', '哪吒闹海', '三毛流浪记', '神笔马良', '中国古代寓言', '伊索寓言', '爱的教育', '看看我们的地球', '查理', '小鲤鱼跳龙门', '尼尔斯骑鹅旅行记', '窄门', '童年', '白洋淀纪事', '愿望的实现', '宝葫芦的秘密', '张居正', '许三观卖血记', '山海经', '查理九世', '论语', '红鞋子', '孤独的小螃蟹', '兄弟', '阳光姐姐', '李四光', '乡土中国', '读读童谣和儿歌'] this.$nextTick(() => { this.tagList = this.hotTagData this.onReady() }) }) }, getMiddleAllData() { this.middleData = [] Promise.all([ this.getLibBookTotal(), this.getUserTotal(), this.getLendingData() ]).then(([libBookTotal, userCardNum, lendingData]) => { const { fansNum, lendingTotal } = lendingData this.middleData.push( { id: 'totalBook', name: '藏书总量', value: libBookTotal, valueArr: this.$parent.formatter(libBookTotal).toString().split('') }, { id: 'cardNum', name: '累计办证', value: userCardNum, valueArr: this.$parent.formatter(userCardNum).toString().split('') }, { id: 'fansNum', name: '今日归还', value: fansNum, valueArr: this.$parent.formatter(fansNum).toString().split('') }, { id: 'lendingNum', name: '今日借出', value: lendingTotal, valueArr: this.$parent.formatter(lendingTotal).toString().split('') } ) this.$parent.timedRefresh(this.middleData, 'middle') }).catch(error => { console.error('获取中间数据失败:', error) }) }, // 馆藏量
getLibBookTotal() { // const params = {
// 'libcode': this.libcode,
// 'starttime': '2000-01-01',
// 'endtime': '2034-01-01'
// }
// return FetchLibBookTotal(params).then(res => {
// const result = JSON.parse(res.data)
// if (result.success & result.resultlist.length !== 0) {
// return result.resultlist.reduce((acc, obj) => acc + obj.GCL, 0)
// } else {
// return 9145
// }
// }).catch(error => {
// console.error('Error', error)
// return 0
// })
return Promise.resolve(9145) }, // 累计办证
getTotalForLibcode(libcode) { const params = { 'libcode': libcode, // 'startdate': this.getFormattedDate(new Date(), -1),
// 'enddate': this.getFormattedDate(new Date()),
'startdate': '2010-01-01', 'enddate': this.getFormattedDate(new Date()), 'isrdtype': 0 } return FetchUsertotal(params).then(res => { const result = JSON.parse(res.data) if (result.success && result.pagedata.length > 0) { return result.pagedata[0].count } else { throw new Error('Failed') } }).catch(error => { console.error('Error', error) return 0 }) }, getUserTotal() { const libraries = ['GD'] const getTotalPromises = libraries.map(libcode => this.getTotalForLibcode(libcode)) return Promise.all(getTotalPromises) .then(counts => counts.reduce((sum, count) => sum + parseInt(count, 10), 0)) .catch(error => { console.error('Error', error) return 0 }) }, getLendingData() { return FetchLendingTotal().then(res => { const result = JSON.parse(res.data) const dwsfData = result.success && result.resultlist.length ? result.resultlist.filter(item => item.LIBCODE === 'DWSF') : [] // 归还
const fansNum = dwsfData.reduce((acc, obj) => acc + obj.HCC_DAY, 0) // 借出
const lendingTotal = dwsfData.reduce((acc, obj) => acc + obj.JCC_DAY, 0) return { fansNum, lendingTotal } }).catch(error => { console.error('获取借阅数据失败:', error) return { fansNum: 0, lendingTotal: 0 } }) }, // 粉丝数量
// getFansNum() {
// return FetchFansCount().then(res => {
// return res.data ? parseInt(res.data) : 0
// }).catch(error => {
// console.error('Error', error)
// return 0
// })
// },
// 今日归还
// getFansNum() {
// return FetchLendingTotal().then(res => {
// const result = JSON.parse(res.data)
// if (result.success && result.resultlist.length !== 0) {
// return result.resultlist.filter(item => item.LIBCODE === 'DWSF').reduce((acc, obj) => acc + obj.HCC_DAY, 0)
// } else {
// return 0
// }
// }).catch(error => {
// console.error('Error', error)
// return 0
// })
// },
// 今日借出
// getLendingTotal() {
// return FetchLendingTotal().then(res => {
// const result = JSON.parse(res.data)
// if (result.success && result.resultlist.length !== 0) {
// return result.resultlist.filter(item => item.LIBCODE === 'DWSF').reduce((acc, obj) => acc + obj.JCC_DAY, 0)
// } else {
// return 0
// }
// }).catch(error => {
// console.error('Error', error)
// return 0
// })
// },
// bottom - 图书推荐
getNewBook() { const params = { 'size': 40 } FetchNewBook(params).then(res => { // 图片地址格式 http://192.168.99.67:8080/downloadFile/qytsg/ae281b90-b100-4541-9379-3e104854652c.png
const linkSrc = process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API this.newList = res.data.map(item => { if (item.nbImgPath) { item.nbImgPath = linkSrc + '/downloadFile' + item.nbImgPath return Promise.resolve(item) } else { const params = { 'sIsbn': item.isbn } return FetchMarcByISBN(params).then(response => { const result = JSON.parse(response.data)[0] if (result.srcurl) { item.nbImgPath = result.srcurl return item } else if (result.img) { item.nbImgPath = 'data:image/png;base64,' + result.img return item } else { return null // 或者根据需求返回其他值或处理
} }) } })
Promise.all(this.newList).then(results => { // 过滤掉返回的空项(根据实际需求)
this.newList = results.filter(item => item !== null) // 一分为二得两行
const halfLength = Math.ceil(this.newList.length / 2) this.listData1 = this.newList.slice(0, halfLength) this.listData2 = this.newList.slice(halfLength) }) }) }, getType1Value() { const type1Item = this.progressData.find(item => item.type === 1) return type1Item ? type1Item.value : 0 }, getType2Value() { const type2Item = this.progressData.find(item => item.type === 2) return type2Item ? type2Item.value : 0 }, getType3Value() { const type3Item = this.progressData.find(item => item.type === 3) return type3Item ? type3Item.value : 0 }, getType4Value() { const type4Item = this.progressData.find(item => item.type === 4) return type4Item ? type4Item.value : 0 },
// 以下生成云标签部分
// 三角函数角度计算
sineCosine(a, b, c) { this.sa = Math.sin(a * this.dtr) this.ca = Math.cos(a * this.dtr) this.sb = Math.sin(b * this.dtr) this.cb = Math.cos(b * this.dtr) this.sc = Math.sin(c * this.dtr) this.cc = Math.cos(c * this.dtr) }, // 设置初始定位
positionAll() { this.$nextTick(() => { // 注意: 所有的在onReady方法中执行的方法都需要$nextTick确保所有的标签都已经渲染
var phi = 0 var theta = 0 var max = this.mcList.length var aTmp = [] var oFragment = document.createDocumentFragment() // 随机排序
for (let i = 0; i < this.tagList.length; i++) { aTmp.push(this.oA[i]) } aTmp.sort(() => { return Math.random() < 0.5 ? 1 : -1 }) for (let i = 0; i < aTmp.length; i++) { oFragment.appendChild(aTmp[i]) } this.oList.appendChild(oFragment) for (let i = 1; i < max + 1; i++) { if (this.distr) { phi = Math.acos(-1 + (2 * i - 1) / max) theta = Math.sqrt(max * Math.PI) * phi } else { phi = Math.random() * (Math.PI) theta = Math.random() * (2 * Math.PI) } this.radius = this.oList.offsetWidth / 2 - 40 // 坐标变换
this.mcList[i - 1].cx = this.radius * Math.cos(theta) * Math.sin(phi) this.mcList[i - 1].cy = this.radius * Math.sin(theta) * Math.sin(phi) this.mcList[i - 1].cz = this.radius * Math.cos(phi) this.oA[i - 1].style.left = this.mcList[i - 1].cx + this.oList.offsetWidth / 2 - this.mcList[i - 1].offsetWidth / 2 + 'px' this.oA[i - 1].style.top = this.mcList[i - 1].cy + this.oList.offsetHeight / 2 - this.mcList[i - 1].offsetHeight / 2 + 'px' } }) }, // 坐标更新 让标签动起来
update() { this.$nextTick(() => { // 注意: 所有的在onReady方法中执行的方法都需要$nextTick确保所有的标签都已经渲染
var a var b // if (this.active) {
a = (Math.min(Math.max(-this.mouseY, -this.size), this.size) / this.radius) * this.tspeed b = (-Math.min(Math.max(-this.mouseX, -this.size), this.size) / this.radius) * this.tspeed // } else {
// a = this.lasta * 0.98
// b = this.lastb * 0.98
// }
this.lasta = a this.lastb = b if (Math.abs(a) <= 0.01 && Math.abs(b) <= 0.01) { return } var c = 0 this.sineCosine(a, b, c) for (var j = 0; j < this.mcList.length; j++) { if (this.mcList[j].on) { continue } var rx1 = this.mcList[j].cx var ry1 = this.mcList[j].cy * this.ca + this.mcList[j].cz * (-this.sa) var rz1 = this.mcList[j].cy * this.sa + this.mcList[j].cz * this.ca var rx2 = rx1 * this.cb + rz1 * this.sb var ry2 = ry1 var rz2 = rx1 * (-this.sb) + rz1 * this.cb var rx3 = rx2 * this.cc + ry2 * (-this.sc) var ry3 = rx2 * this.sc + ry2 * this.cc var rz3 = rz2 this.mcList[j].cx = rx3 this.mcList[j].cy = ry3 this.mcList[j].cz = rz3 var per = this.d / (this.d + rz3) this.mcList[j].x = (this.howElliptical * rx3 * per) - (this.howElliptical * 2) this.mcList[j].y = ry3 * per this.mcList[j].scale = per var alpha = per alpha = (alpha - 0.6) * (10 / 6) this.mcList[j].alpha = alpha * alpha * alpha - 0.2 // this.mcList[j].alpha = (this.mcList[j].alpha - 0.6) * (10 / 6)
this.mcList[j].zIndex = Math.ceil(100 - Math.floor(this.mcList[j].cz)) } this.doPosition() this.depthSort() }) }, //
doPosition() { this.$nextTick(() => { // 注意: 所有的在onReady方法中执行的方法都需要$nextTick确保所有的标签都已经渲染
var l = this.oList.offsetWidth / 2 var t = this.oList.offsetHeight / 2 for (var i = 0; i < this.mcList.length; i++) { this.oA[i].style.left = this.mcList[i].cx + l - this.mcList[i].offsetWidth / 2 + 'px' this.oA[i].style.top = this.mcList[i].cy + t - this.mcList[i].offsetHeight / 2 + 'px' // this.oA[i].style.fontSize = Math.ceil(12 * this.mcList[i].scale / 2) + 8 + 'px'
this.oA[i].style.filter = 'alpha(opacity=' + 100 * this.mcList[i].alpha + ')' this.oA[i].style.opacity = this.mcList[i].alpha } }) }, depthSort() { this.$nextTick(() => { // 注意: 所有的在onReady方法中执行的方法都需要$nextTick确保所有的标签都已经渲染
var aTmp = [] for (let i = 0; i < this.oA.length; i++) { aTmp.push(this.oA[i]) } aTmp.sort(function(vItem1, vItem2) { if (vItem1.cz > vItem2.cz) { return -1 } else if (vItem1.cz < vItem2.cz) { return 1 } else { return 0 } }) for (let i = 0; i < aTmp.length; i++) { aTmp[i].style.zIndex = i } }) }, onReady() { this.$nextTick(() => { this.oList = this.$refs.tagcloudall this.oA = this.oList.getElementsByTagName('a') var oTag = null for (var i = 0; i < this.oA.length; i++) { oTag = {} oTag.offsetWidth = this.oA[i].offsetWidth oTag.offsetHeight = this.oA[i].offsetHeight this.mcList.push(oTag) } this.sineCosine(0, 0, 0) this.positionAll() this.oList.onmouseover = () => { this.active = true } this.oList.onmouseout = () => { this.active = false } // this.oList.onmousemove = (event) => {
// var oEvent = window.event || event
// this.mouseX = oEvent.clientX - (this.oList.offsetLeft + this.oList.offsetWidth / 2)
// this.mouseY = oEvent.clientY - (this.oList.offsetTop + this.oList.offsetHeight / 2)
// this.mouseX /= 5
// this.mouseY /= 5
// }
setInterval(() => { this.update() }, 40) // 定时器执行 不能写setInterval(this.update(), 30)
}) } }}
</script>
<style lang="scss">@import "~@/assets/styles/index.scss";@import "~@/assets/styles/font-some.css";#tagscloud{ width:5rem; height:4.75rem; position:relative; margin:0 auto;}
#tagscloud a{ position:absolute; top:0px; left:0px; line-height:24px; text-align:center; font-size:18px; padding:3px 5px; display:inline-block; text-wrap: nowrap;}#tagscloud a.tagc1{ // border: 1px solid #30ADA6;
// background-color: #106B66;
// color: #51EAE2;
color: #F4C263;}
#tagscloud a.tagc2{ font-size: 22px; // border: 1px solid #3A64BE;
// background: rgba(16,45,107,0.7);
color: #7EA7FF;}
#tagscloud a.tagc3{ font-size: 18px; // border: 1px solid #9439B6;
// background: rgba(74,18,95,0.8);
// color: #CD63F4;
color: #7EA7FF;}
#tagscloud a.tagc4{ font-size: 26px; // border: 1px solid #C2943C;
// background: rgba(107,76,16,0.7);
color: #F4C263;}
.tagcloud { width: 10rem; height: 5rem; overflow: hidden; p{ padding: .0625rem; border-bottom: 2px dashed rgba(24, 77, 97, 0.5); span{ display: block; padding: .075rem 8px; white-space: nowrap; } &.color1{ border-top: 2px dashed #1F6374; border-left: 3px dashed #184D61; border-right: 3px dashed #184D61; span{ border: 1px solid #30ADA6; background-color: #106B66; color: #51EAE2; } } &.color2{ border-top: 2px dashed #203F7F; border-left: 3px dashed #102857; border-right: 3px dashed #102857; span{ border: 1px solid #3A64BE; background: rgba(16,45,107,0.7); color: #7EA7FF; } } &.color3{ border-top: 2px dashed #613689; border-left: 3px dashed #4C2E75; border-right: 3px dashed #4C2E75; span{ border: 1px solid #9439B6; background: rgba(74,18,95,0.8); color: #CD63F4; } } &.color4{ border-top: 2px dashed #6A5735; border-left: 3px dashed #655435; border-right: 3px dashed #655435; span{ border: 1px solid #C2943C; background: rgba(107,76,16,0.7); color: #F4C263; } } }}
.scrollBox{ flex: 1; height: calc(100%); box-sizing: border-box; margin-left: 0.45rem; overflow: hidden; .seamless01{ margin-bottom: .35rem; } ul{ display: flex; height: 2rem; // overflow: hidden;
li{ width: 1.375rem; height: 2rem; margin-right: .7375rem; cursor: pointer; .bord{ display: flex; flex-wrap: wrap; justify-content: space-around; align-items: center; .book-img{ width: 1.375rem; height: 2rem; // background: url('~@/assets/images/book_03.png') no-repeat center center;
// background-size: contain;
display: flex; align-items: center; overflow: hidden; img{ display: block; width: 100%; } } } } }
}
</style>
|