|
|
@@ -50,7 +50,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getFeaturedArticles } from '@/utils/api.js'
|
|
|
+import { getRecommendedArticles } from '@/utils/api.js'
|
|
|
var DIMENSION_MAP = {
|
|
|
body: { name: '身', color: '#FF8C42' },
|
|
|
mind: { name: '心', color: '#FF6B9D' },
|
|
|
@@ -71,6 +71,7 @@ export default {
|
|
|
props: {
|
|
|
articles: { type: Array, default: function() { return [] } },
|
|
|
isLoggedIn: { type: Boolean, default: false },
|
|
|
+ dimensionCode: { type: String, default: null },
|
|
|
colors: { type: Array, default: function() { return defaultGradientColors } }
|
|
|
},
|
|
|
data: function() {
|
|
|
@@ -92,20 +93,27 @@ export default {
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ dimensionCode: function(newVal, oldVal) {
|
|
|
+ if (newVal !== oldVal && newVal && this.isLoggedIn) {
|
|
|
+ this.loadArticles()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
mounted: function() {
|
|
|
- if (!this.articles || this.articles.length === 0) {
|
|
|
+ if (this.isLoggedIn && (!this.articles || this.articles.length === 0) && this.dimensionCode) {
|
|
|
this.loadArticles()
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
loadArticles: function() {
|
|
|
var self = this
|
|
|
+ if (!self.isLoggedIn) return
|
|
|
self.loading = true
|
|
|
- getFeaturedArticles({ size: 3 }).then(function(res) {
|
|
|
+ getRecommendedArticles({ type: 'article', dimensionCode: self.dimensionCode, size: 5 }).then(function(res) {
|
|
|
self.loading = false
|
|
|
- if (res && res.code === 200 && res.data) {
|
|
|
- var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
|
|
|
- self.selfArticles = list.slice(0, 3)
|
|
|
+ if (res && res.code === 200 && res.data && res.data.recommendations) {
|
|
|
+ self.selfArticles = res.data.recommendations.slice(0, 5)
|
|
|
}
|
|
|
}).catch(function() {
|
|
|
self.loading = false
|