470 lines
14 KiB
JavaScript
470 lines
14 KiB
JavaScript
// pages/projectAllList/projectAllList.js
|
||
const miucms = require('../../utils/miucms.js');
|
||
import common from '../../utils/commonMethod'
|
||
import util from "../../utils/util"
|
||
var app = getApp()
|
||
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
informationState: false, // 授权后可能需要弹出完成信息框 个人背景那些
|
||
islogin: false, //是否登录
|
||
isloginBtnState: false, // 登录弹窗的状态
|
||
realizeState: false, // 了解弹窗状态
|
||
user: {},
|
||
classifyType: "school", // school subject
|
||
classify: "school", // school subject
|
||
comData: [],
|
||
com: {},
|
||
comOption: {},
|
||
comSum: 0,
|
||
majData: [],
|
||
maj: {},
|
||
majOption: {},
|
||
majSum: 0,
|
||
majObj: {},
|
||
rankingskeyVlaue: {},
|
||
majPitch: {
|
||
major: "",
|
||
organ: "",
|
||
},
|
||
|
||
screenState: false, // 选择框的状态
|
||
|
||
organList: [{
|
||
name: "QS",
|
||
key: "qs",
|
||
text: "由英国的Quacquarelli Symonds公司编制,侧重于学术声誉、雇主声誉、师生比例等指标"
|
||
}, {
|
||
name: "泰晤士",
|
||
key: "times",
|
||
text: "以其全面的数据收集和分析著称,涵盖了教学、研究、国际化等多个方面"
|
||
}, {
|
||
name: "U.S. News",
|
||
key: "usnews",
|
||
text: "由美国新闻与世界报道出版,注重学术研究影响力、学术声誉等",
|
||
}, {
|
||
name: "软科",
|
||
key: "ruanke",
|
||
text: "由中国上海交通大学发布,强调科研表现和学术影响力",
|
||
}, {
|
||
name: "麦考林",
|
||
key: "mecoxLane",
|
||
text: "以全面和权威著称,主要关注加拿大国内大学的综合表现,并将大学分为医博类、综合类和基础类",
|
||
}],
|
||
|
||
letterList: {}, // 字母列表
|
||
screen_data: {},
|
||
letterKey: "A",
|
||
letterFixed: false,
|
||
isFirstPattern: true, // 是否是首屏模式
|
||
|
||
rankingKey: common.rankingKey,
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
windowHeight: 0,
|
||
totalTopHeight: 0,
|
||
onLoad(options) {
|
||
miucms.pageStart(app).then(() => {
|
||
const screen_data = app.globalData.screen_data
|
||
const user = app.globalData.user
|
||
this.setData({
|
||
islogin: user.uid > 0 ? true : false,
|
||
user,
|
||
screen_data,
|
||
})
|
||
|
||
this.windowHeight = screen_data.windowHeight
|
||
this.totalTopHeight = screen_data.totalTopHeight
|
||
|
||
common.xgBasicData(this, app).then(data => {
|
||
this.setData({
|
||
rankingskeyVlaue: data.rankings || {},
|
||
})
|
||
this.getRankings()
|
||
this.getComprehensiveRanking()
|
||
this.getMajorRanking()
|
||
})
|
||
})
|
||
},
|
||
|
||
// 专业
|
||
getMajorRanking() {
|
||
util.wxget("https://api.gter.net/v1/ranking/getMajorRanking", {}).then(res => {
|
||
if (res.code != 200) return
|
||
const data = res.data
|
||
let list = data.list || []
|
||
list.forEach(element => {
|
||
element['systemObj'] = {}
|
||
element.lists.forEach(ele => {
|
||
if (!Array.isArray(element['systemObj'][ele.system])) element['systemObj'][ele.system] = []
|
||
element['systemObj'][ele.system].push(ele)
|
||
})
|
||
})
|
||
|
||
list.sort((a, b) => {
|
||
if (a.subject < b.subject) return -1;
|
||
if (a.subject > b.subject) return 1;
|
||
return 0;
|
||
});
|
||
|
||
// 为每个对象添加首字母标识
|
||
let currentInitial = null;
|
||
list.forEach(item => {
|
||
const initial = item.subject[0].toUpperCase()
|
||
if (initial !== currentInitial) {
|
||
item.initial = initial;
|
||
currentInitial = initial;
|
||
}
|
||
})
|
||
|
||
// 用于记录每个首字母的数量
|
||
const initialCount = {};
|
||
// 为每个对象添加首字母标识并统计首字母数量
|
||
list.forEach(item => {
|
||
const initial = item.subject[0].toUpperCase();
|
||
if (!initialCount[initial]) {
|
||
initialCount[initial] = {
|
||
initial: 0,
|
||
sum: 0,
|
||
}
|
||
}
|
||
initialCount[initial]['initial'] += 1
|
||
initialCount[initial]['sum'] += Object.keys(item.systemObj).length || 0
|
||
});
|
||
|
||
const result = {};
|
||
|
||
list.forEach(item => {
|
||
const firstLetter = item.subject[0].toUpperCase();
|
||
if (!result[firstLetter]) {
|
||
result[firstLetter] = [];
|
||
}
|
||
result[firstLetter].push(item);
|
||
});
|
||
|
||
this.setData({
|
||
majSum: data.count,
|
||
majData: result,
|
||
letterList: initialCount,
|
||
})
|
||
})
|
||
},
|
||
|
||
// 综合
|
||
getComprehensiveRanking() {
|
||
util.wxget("https://api.gter.net/v1/ranking/getComprehensiveRanking", {}).then(res => {
|
||
if (res.code != 200) return
|
||
const data = res.data
|
||
this.setData({
|
||
comSum: data.count,
|
||
comData: data.list,
|
||
})
|
||
})
|
||
},
|
||
|
||
// 获取 配置信息
|
||
getRankings() {
|
||
wx.showLoading({
|
||
title: '加载中...',
|
||
})
|
||
util.wxget("https://api.gter.net/v1/program/rankings", {}).then(res => {
|
||
if (res.code != 200) return
|
||
const data = res.data
|
||
|
||
const comprehensive = data.comprehensive || {}
|
||
// let com = this.data.com
|
||
// com['jg'] = Object.keys(comprehensive)[0]
|
||
// let yearsSet = [...this.collectYears(comprehensive)].sort((a, b) => b - a);
|
||
// com['year'] = yearsSet[0]
|
||
|
||
const discipline = data.discipline || {}
|
||
// let maj = this.data.maj
|
||
// const [dOrganizationKey, dOrganizationValue] = Object.entries(discipline)[0]
|
||
// maj['jg'] = dOrganizationKey
|
||
// maj['major'] = Object.entries(dOrganizationValue)[0][0]
|
||
// const dYear = [...this.collectYears(discipline)].sort((a, b) => b - a);
|
||
// maj['year'] = dYear[0]
|
||
|
||
this.setData({
|
||
comOption: comprehensive,
|
||
// com,
|
||
majOption: discipline,
|
||
// maj,
|
||
isInitFinish: true,
|
||
})
|
||
}).finally(() => wx.hideLoading())
|
||
},
|
||
|
||
// 计算对象里对象的数量
|
||
countKeysInNestedObjects(obj) {
|
||
let count = 0;
|
||
for (let key in obj) {
|
||
if (obj.hasOwnProperty(key)) {
|
||
const value = obj[key];
|
||
if (typeof value === 'object' && value !== null) {
|
||
count += Object.keys(value).length;
|
||
count += this.countKeysInNestedObjects(value);
|
||
}
|
||
}
|
||
}
|
||
return count;
|
||
},
|
||
|
||
// 计算出 对象 所有 二级 key 不重复
|
||
collectYears(obj, arr = new Set()) {
|
||
for (let key in obj) {
|
||
if (obj.hasOwnProperty(key)) {
|
||
if (!isNaN(key) && key.length === 4) arr.add(key);
|
||
const value = obj[key];
|
||
if (typeof value === 'object' && value !== null) this.collectYears(value, arr);
|
||
}
|
||
}
|
||
return [...arr];
|
||
},
|
||
|
||
openYear(e) {
|
||
const major = e.currentTarget.dataset.major
|
||
const organ = e.currentTarget.dataset.organ
|
||
this.setData({
|
||
majPitch: {
|
||
major,
|
||
organ,
|
||
}
|
||
})
|
||
},
|
||
|
||
// 选择专业排名
|
||
selectMaj(e) {
|
||
let major = e.currentTarget.dataset.major
|
||
let organ = e.currentTarget.dataset.organ
|
||
const year = e.currentTarget.dataset.year
|
||
major = encodeURIComponent(major)
|
||
organ = encodeURIComponent(organ)
|
||
common.goPage(`/pages/projectList/projectList?type=subject&system=${organ}&subject=${major}&year=${year}`)
|
||
this.closeYear()
|
||
},
|
||
|
||
// 选择综合排名
|
||
selectCom(e) {
|
||
let mechanism = e.currentTarget.dataset.mechanism || ''
|
||
const year = e.currentTarget.dataset.year
|
||
mechanism = encodeURIComponent(mechanism)
|
||
common.goPage(`/pages/projectList/projectList?type=school&mechanism=${mechanism}&year=${year}`)
|
||
},
|
||
|
||
closeYear() {
|
||
this.setData({
|
||
majPitch: {
|
||
major: "",
|
||
organ: "",
|
||
}
|
||
})
|
||
},
|
||
|
||
|
||
// 切换了解状态
|
||
cutRealizeState() {
|
||
this.setData({
|
||
realizeState: !this.data.realizeState,
|
||
})
|
||
},
|
||
|
||
// 切换查看类型
|
||
cutClassify(e) {
|
||
const classify = e.currentTarget.dataset.type
|
||
if (classify == this.data.classify) return
|
||
|
||
this.setData({
|
||
classify,
|
||
}, () => {
|
||
if (classify == "subject" && JSON.stringify(this.sideHeight) == "{}") {
|
||
setTimeout(() => {
|
||
this.calculateSectionTops()
|
||
}, 500)
|
||
}
|
||
})
|
||
},
|
||
|
||
// 点击
|
||
cutScreenState(e) {
|
||
const type = e.currentTarget.dataset.type
|
||
this.setData({
|
||
classifyType: type,
|
||
screenState: !this.data.screenState,
|
||
})
|
||
},
|
||
|
||
// 点击 筛选的选好了
|
||
haveChosen(e) {
|
||
const detail = e.detail || {}
|
||
const classify = this.data.classifyType
|
||
this.setData({
|
||
[classify == "school" ? 'com' : 'maj']: detail,
|
||
screenState: false,
|
||
classifyType: "",
|
||
})
|
||
|
||
const jg = encodeURIComponent(detail.jg || '')
|
||
|
||
if (classify == "school") common.goPage(`/pages/projectList/projectList?type=school&mechanism=${jg}&year=${detail.year}`)
|
||
else common.goPage(`/pages/projectList/projectList?type=subject&system=${jg}&subject=${encodeURIComponent(detail.major || '')}&year=${detail.year}`)
|
||
},
|
||
|
||
userClickLogin(e) {
|
||
let data = e.detail.data
|
||
this.setData({
|
||
islogin: true,
|
||
isloginBtnState: false,
|
||
informationState: data.regdatastep == 'success' ? false : true,
|
||
})
|
||
|
||
this.onLoad(this.data.options)
|
||
},
|
||
|
||
// 子组件传值 修改 完善信息组件的状态
|
||
revampInformationState() {
|
||
this.setData({
|
||
informationState: false
|
||
})
|
||
},
|
||
|
||
// 关闭授权登录事件
|
||
popClose() {
|
||
this.setData({
|
||
isloginBtnState: !this.data.isloginBtnState
|
||
})
|
||
},
|
||
|
||
openLoginState() {
|
||
this.setData({
|
||
isloginBtnState: true
|
||
})
|
||
},
|
||
|
||
sideHeight: {},
|
||
// 计算每个字母区域的位置
|
||
calculateSectionTops() {
|
||
const screen_data = this.data.screen_data
|
||
const query = wx.createSelectorQuery()
|
||
let headHeight = screen_data.totalTopHeight || 0
|
||
query.select(`.header`).boundingClientRect()
|
||
query.select(`.item-header-screen`).boundingClientRect()
|
||
query.select(`.item-header-all`).boundingClientRect()
|
||
query.select(`.screen`).boundingClientRect()
|
||
|
||
query.exec(res => {
|
||
if (!res) return
|
||
this.topBtnSistance = res[0].height + headHeight
|
||
res.forEach(element => {
|
||
headHeight += element.height
|
||
})
|
||
headHeight += util.rpxTopx(405)
|
||
let sideHeight = {}
|
||
const query2 = wx.createSelectorQuery()
|
||
query2.selectAll(`.node-item`).boundingClientRect(rect => {
|
||
if (!rect) return
|
||
let h = headHeight
|
||
rect.forEach(element => {
|
||
sideHeight[element.id] = h
|
||
h += element.height
|
||
})
|
||
this.sideHeight = sideHeight
|
||
}).exec();
|
||
})
|
||
},
|
||
|
||
// 点击字母跳转
|
||
jumpToIndex(e) {
|
||
const key = e.currentTarget.dataset.key
|
||
wx.pageScrollTo({
|
||
offsetTop: -this.totalTopHeight,
|
||
selector: `.major .list .item${ key }`,
|
||
})
|
||
},
|
||
|
||
topBtnSistance: 248, //
|
||
onPageScroll(e) {
|
||
const scrollTop = e.scrollTop
|
||
const sideHeight = this.sideHeight
|
||
const sideHeightList = Object.keys(sideHeight) || []
|
||
if (sideHeightList.length == 0) return
|
||
const keys = Object.keys(sideHeight);
|
||
// 对键数组进行倒序排列
|
||
let closestValue = keys.reduce((acc, key) => {
|
||
const diff = sideHeight[key] - scrollTop;
|
||
if (diff <= this.totalTopHeight + 20) return key
|
||
return acc;
|
||
}, null);
|
||
|
||
const letterKey = closestValue || 'A'
|
||
if (letterKey != this.data.letterKey) {
|
||
this.setData({
|
||
letterKey,
|
||
})
|
||
}
|
||
|
||
if (scrollTop > this.topBtnSistance && this.data.isFirstPattern) {
|
||
// 这里是 首屏的
|
||
this.setData({
|
||
isFirstPattern: false,
|
||
})
|
||
} else if (scrollTop < this.topBtnSistance && !this.data.isFirstPattern) {
|
||
this.setData({
|
||
isFirstPattern: true,
|
||
})
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
return {
|
||
title: "【寄托港校项目库】- 世界排行榜",
|
||
}
|
||
},
|
||
|
||
onShareTimeline() {
|
||
return {
|
||
title: "【寄托港校项目库】- 世界排行榜",
|
||
}
|
||
},
|
||
}) |