第一次提交
This commit is contained in:
40
core/mixins/app.js
Executable file
40
core/mixins/app.js
Executable file
@@ -0,0 +1,40 @@
|
||||
import Vue from 'vue'
|
||||
import { mapGetters } from 'vuex'
|
||||
import store from '@/store/index'
|
||||
import platform from '@/core/platform'
|
||||
|
||||
// 字符串驼峰转中划线
|
||||
const formatToLine = value => {
|
||||
return value.replace(/([A-Z])/g, '-$1').toLowerCase()
|
||||
}
|
||||
|
||||
// 主题样式 (因小程序端不支持styleObject语法,所以需要转换成字符串)
|
||||
const appTheme2Str = appTheme => {
|
||||
let str = ''
|
||||
for (const index in appTheme) {
|
||||
const name = formatToLine(index)
|
||||
str += `--${name}:${appTheme[index]};`
|
||||
}
|
||||
return str
|
||||
}
|
||||
import dayjs from "dayjs"
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
platform
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['appTheme']),
|
||||
appThemeStyle() {
|
||||
const appTheme = store.getters.appTheme
|
||||
return appTheme2Str(appTheme)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
computedAge(birthday){
|
||||
return dayjs().diff(dayjs(birthday), 'year')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
72
core/mixins/notice.js
Normal file
72
core/mixins/notice.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import {
|
||||
mapGetters
|
||||
} from 'vuex'
|
||||
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
pageActive: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['conversations','unReadMessageCount', 'unReadCommentNumber']),
|
||||
},
|
||||
watch: {
|
||||
unReadMessageCount(val) {
|
||||
if (this.pageActive) {
|
||||
this.setTabbar()
|
||||
}
|
||||
},
|
||||
unReadCommentNumber(val){
|
||||
if (this.pageActive) {
|
||||
this.setPyqTabbar()
|
||||
}
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.pageActive = true;
|
||||
this.setTabbar()
|
||||
},
|
||||
onHide() {
|
||||
this.pageActive = false;
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 设置tabbar的未读消息数量
|
||||
*/
|
||||
setTabbar() {
|
||||
|
||||
if (this.unReadMessageCount > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: 3,
|
||||
text: this.unReadMessageCount + '',
|
||||
fail: (err) => {
|
||||
console.log("unReadCount: ", err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: 3
|
||||
})
|
||||
}
|
||||
},
|
||||
setPyqTabbar() {
|
||||
console.log("this.unReadCommentNumber: ",this.unReadCommentNumber);
|
||||
if (this.unReadCommentNumber > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: 2,
|
||||
text: this.unReadCommentNumber + '',
|
||||
fail: (err) => {
|
||||
console.log("unReadCount: ", err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: 2
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
73
core/mixins/tabbar.js
Normal file
73
core/mixins/tabbar.js
Normal file
@@ -0,0 +1,73 @@
|
||||
import {
|
||||
mapGetters
|
||||
} from 'vuex'
|
||||
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
pageActive: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['conversations','unReadMessageCount', 'unReadCommentNumber', 'conversationArr','unReadLikeNumber','unReadLikeMeNumber','unReadLookNumber']),
|
||||
},
|
||||
watch: {
|
||||
unReadMessageCount(val) {
|
||||
if (this.pageActive) {
|
||||
this.setTabbar()
|
||||
}
|
||||
},
|
||||
unReadCommentNumber(val){
|
||||
if (this.pageActive) {
|
||||
this.setPyqTabbar()
|
||||
}
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.pageActive = true;
|
||||
this.setTabbar()
|
||||
this.setPyqTabbar()
|
||||
},
|
||||
onHide() {
|
||||
this.pageActive = false;
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 设置tabbar的未读消息数量
|
||||
*/
|
||||
setTabbar() {
|
||||
|
||||
if (this.unReadMessageCount > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: 2,
|
||||
text: this.unReadMessageCount + '',
|
||||
fail: (err) => {
|
||||
console.log("unReadCount: ", err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: 2
|
||||
})
|
||||
}
|
||||
},
|
||||
setPyqTabbar() {
|
||||
console.log("this.unReadCommentNumber: ",this.unReadCommentNumber);
|
||||
if (this.unReadCommentNumber > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: 1,
|
||||
text: this.unReadCommentNumber + '',
|
||||
fail: (err) => {
|
||||
console.log("unReadCount: ", err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: 1
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user