const Magix = require('magix') const View = require('dmp-new/view') Magix.applyStyle('@./rank.less') Magix.applyStyle('@./special.less') module.exports = View.extend({ tmpl: '@special.html', init (options) { this.options = options }, async render () { try { const _specials = await this.getSpecial() const models = [] for (const special of _specials) { models.push({ name: 'api_tag_topic_get_get', params: { topicId: special.id } }) } const resps = await this.fetch(models) let specials = [] for (const resp of resps) { const data = resp.get('data.data', {}) // 标签取前三个 data._tags = [] let i = 0 for (const sub of data.subjectList) { for (const tag of sub.tagList) { if (i < 3) { data._tags.push(tag) i++ } } } specials.push(data) } // 专题取前三个 specials = specials.slice(0, 3) this.updater.digest({ specials }) // let data = model.get('data', {}) // return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, // 获取标签专题 async getSpecial () { const self = this const urlParams = { pageSize: 20 } try { const [model] = await this.fetch([{ name: 'api_tag_topic_list_get', urlParams: urlParams }]) const list = [] model.get('data.list', []).forEach((item, i) => { item.list.forEach((_item, _i) => { let month = _item.publishTime.split('-')[1] // 月份显示处理 if (month.indexOf('0') === 0) { month = month.slice(1) } _item.month = month list.push(_item) }) }) if (list.length === 0) { self.updater.digest({ list }) return } const maxCount = 3 if (list.length > maxCount) { list.length = maxCount } return list } catch (error) { console.error(error) } }, 'showTopic' (e) { const { id, title } = e.params this.showTopic(id, title) }, showTopic (id, title) { const viewPath = '@./tag-topic' const viewOptions = { id, title, callback: (topicId, topicTitle) => { this.showTopic(topicId, topicTitle) } } const dialogOptions = { width: 888, header: { title: `标签专题:${title}` }, footer: { cancel: false, enter: false } } this.mxModal(viewPath, viewOptions, dialogOptions) } })