min-project/component/indexSidebar/indexSidebar.js

220 lines
6.4 KiB
JavaScript
Raw Normal View History

2024-12-12 04:14:09 +00:00
// template/indexSidebar/indexSidebar.js
const util = require('../../utils/util')
const common = require('../../utils/commonMethod')
const app = getApp()
Component({
/**
* 组件的属性列表
*/
properties: {
isInitFinish: {
type: Boolean,
observer(res) {
if (res) {
this.openSidebarTwoHide()
const ishongkongoffer = app.globalData.user.ishongkongoffer
this.setData({
gtergreenonionqrcode: app.globalData.gtergreenonionqrcode
})
if (this.data.ishongkongoffer == 0) {
this.setData({
ishongkongoffer,
})
}
}
},
value: false,
},
sidebarType: {
type: String,
value: "offer",
},
islogin: {
type: Boolean,
value: true
},
followschool: {
type: Number,
observer(res) {
if (res) this.judgeIsHK(res)
}
},
},
/**
* 组件的初始数据
*/
data: {
helperPopState: false, // offer捷报右侧-申请小助手弹窗的状态
isSidebarShowState: true, // 侧边栏的展开状态 相反的是 收起
sidebarState: 1, // 侧边栏有三种内容状态 1 只有申请助手 2 申请 + offer按钮 3 申请 + offer按钮 + 置顶
sidebarTimer: null, // 侧边栏的定时器
btnText: {
offer: "Offer\n捷报",
summary: "申请\n总结",
mj: "发布\n面经",
vote: "创建\n投票",
questions: "我要\n提问",
find: "我要\n发布",
note: "发布\n笔记",
},
opinionState: false, // 意见反馈 弹窗显示状态
ishongkongoffer: 0, // 是否报告 香港 offer
gtergreenonionqrcode: "", // 群 二维码
groupState: false, // 群 弹窗显示状态
},
/**
* 组件的方法列表
*/
methods: {
// 判断显示
judgeIsHK(value) {
if (this.data.isInitFinish) {
const arr = [308, 309, 310, 311, 312, 313, 314, 315, 316, 453, 1662, 2971, 2972]
value = Number(value)
let ishongkongoffer = 0
if (arr.includes(value)) ishongkongoffer = 1
this.setData({
ishongkongoffer,
})
} else setTimeout(() => this.judgeIsHK(value), 1000)
},
// 开启两秒后收起
openSidebarTwoHide() {
clearTimeout(this.data.sidebarTimer)
if (!this.data.isSidebarShowState) {
this.setData({
isSidebarShowState: true
})
}
this.data.sidebarTimer = setTimeout(() => {
this.setData({
isSidebarShowState: false
})
}, 2000);
},
// 专门处理侧边栏的事件 隐藏消失
sidebarShowHide(e) {
clearTimeout(this.data.sidebarTimer)
if (!this.data.isSidebarShowState) {
this.openSidebarTwoHide()
return
}
const type = e.currentTarget.dataset.type
if (type == 'group') {
// const url = "https://form.gter.net/D8i0iS5uXCWG#/qr"
// common.goPage(`/pages/webview/webview?url=${url}`)
this.setData({
groupState: true,
})
util.statistics({
name: "side-group"
})
return
}
if (type == 'offer') {
wx.navigateToMiniProgram({
appId: "wxa9296b07391c2bc7",
page: "/pages/victoryList/victoryList"
})
util.statistics({
name: "side-offer"
})
return
}
2024-12-12 04:14:09 +00:00
if (type == 'gx') {
wx.navigateToMiniProgram({
appId: "wxcf0a799771cf2ae6",
page: "/pages/index/index"
})
util.statistics({
name: "side-gx"
})
return
}
if (type == 'top') {
wx.pageScrollTo({
scrollTop: 0
})
return
}
if (type == 'issue') {
if (!this.data.islogin) {
this.triggerEvent("openLogin")
return
}
const type = this.data.sidebarType || ''
if (type == 'questions') {
this.triggerEvent('openSelectTheme')
return
}
let url = '/pagesLoginRequired/pages/postOffer/postOffer'
if (type == 'summary') url = '/pages/summaryPost/summaryPost'
else if (type == 'mj') url = '/pagesSquare/pages/mjIssue/mjIssue'
else if (type == 'vote') url = '/pagesSquare/pages/voteCcreate/voteCcreate'
else if (type == 'find') url = '/pagesSquare/pages/publish/publish'
else if (type == 'note') url = '/pages/treeIssue/treeIssue'
wx.navigateTo({
url
})
}
if (type == 'apply') {
this.setData({
helperPopState: true
})
// 调用统计代码
util.statistical({
type: "documentassistant"
}).then(res => {})
}
if (type == 'xg') {
this.setData({
opinionState: true,
})
}
this.openSidebarTwoHide()
},
// 关闭 申请小助手的弹窗
closeHelperPopState() {
this.setData({
// sidebarState: 1,
helperPopState: false
})
},
closeOpinion() {
this.setData({
opinionState: false,
})
},
closeGroup() {
this.setData({
groupState: false,
})
},
}
})