外观
selection-search.js
js
import { Page, Host, UI } from '@kodet/content';
/** @param {import('@kodet/content').ContentApp} app */
export function registerSelectionSearch(app) {
const formats = app.searchFilter({ key: 'formats', name: '内容格式', multiple: true,
items: [{ name: '文字', value: 'text' }, { name: '图文', value: 'image' }], defaultValue: ['text'],
onChange(ctx) { console.log('内容格式', ctx.previousValue, ctx.value); },
});
const scope = app.searchFilter({ key: 'scope', name: '搜索范围',
items: [{ name: '标题', value: 'title' }, { name: '作者', value: 'author' }], defaultValue: 'title',
async onChange(ctx) {
console.log('搜索范围', ctx.previousValue, ctx.value);
await formats.update({ value: ctx.value === 'author' ? ['text'] : ['text', 'image'] });
},
});
app.page('selection', '多选与搜索').filter({
name: '标签', key: 'tags', style: 'chipsWrap', multiple: true,
items: [{ name: '冒险', value: 'adventure' }, { name: '日常', value: 'daily' }],
}).load(ctx => Page.create().next(null).blocks(b => {
b.text('筛选快照:' + JSON.stringify(ctx.filters));
b.select({ id: 'preferences', multiple: true, name: '阅读偏好', desc: '直接点击,允许不选',
values: [{ name: '文字', value: 'text' }, { name: '图文', value: 'image' }], defaultValue: [], persist: 'reading.preferences',
onChange(event) { console.log(event.value, event.target.value); },
});
b.entry({ name: '更新当前标题和说明', onClick: () => UI.page().update({ title: '多选与搜索:已更新', desc: '仅更新当前子页面实例' }) });
b.entry({ name: '清空偏好', onClick: () => UI('preferences').update({ value: [] }) });
b.entry({ name: '切换作者范围并搜索', async onClick() {
await scope.update({ value: 'author' }); await Host.openSearch('山间来信').run();
} });
b.entry({ name: '打开搜索记录', onClick: Host.openSearch() });
}));
app.search('offline', '离线搜索').load(ctx => Page.create().next(null).blocks(b => {
b.text(JSON.stringify({ keyword: ctx.keyword, searchFilters: ctx.searchFilters, filters: ctx.filters }));
b.list({ style: 'info_tile' }).item({ name: '山间来信', desc: '当前条件:' + ctx.searchFilters.scope });
}));
}