Files
pk-lab-xhs/pages/index/index.js
T
codex-bot 36aee09dfa
Verify mini program and deploy preview / verify-deploy (push) Successful in 50s
feat: add animated choice modes and bracket editor
2026-09-19 04:11:21 +08:00

32 lines
1.3 KiB
JavaScript

var api = require('../../utils/api');
Page({
data: { tests: [], visibleTests: [], keyword: '', loading: true, error: '' },
onLoad: function () { this.loadTests(); },
onPullDownRefresh: function () { this.loadTests(true); },
loadTests: function (refreshing) {
var self = this;
api.request('/api/v1/tests').then(function (tests) {
self.setData({ tests: tests, visibleTests: tests, loading: false, error: '' });
}).catch(function (error) {
self.setData({ loading: false, error: error.message || '加载失败' });
}).then(function () {
if (refreshing) xhs.stopPullDownRefresh();
}, function () {
if (refreshing) xhs.stopPullDownRefresh();
});
},
openTest: function (event) {
xhs.navigateTo({ url: '/pages/test/test?slug=' + event.currentTarget.dataset.slug });
},
search: function (event) {
var keyword = (event.detail.value || '').trim().toLowerCase();
var visible = this.data.tests.filter(function (item) {
return (item.title + ' ' + item.subtitle).toLowerCase().indexOf(keyword) >= 0;
});
this.setData({ keyword: keyword, visibleTests: visible });
},
openDiscover: function () { xhs.navigateTo({ url: '/pages/discover/discover' }); },
openMe: function () { xhs.navigateTo({ url: '/pages/me/me' }); }
});