init: initial commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// pages/wiki/index.js
|
||||
import { MOCK_WIKI } from '../../utils/mockData';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
wikiList: [],
|
||||
displayedList: [],
|
||||
searchQuery: '',
|
||||
activeCategory: '全部',
|
||||
showIdentifyModal: false
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.setData({ wikiList: MOCK_WIKI });
|
||||
this.filterList();
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (typeof this.getTabBar === 'function' &&
|
||||
this.getTabBar()) {
|
||||
this.getTabBar().setData({ selected: 3 });
|
||||
}
|
||||
},
|
||||
|
||||
onSearchInput(e) {
|
||||
// TDesign search event: e.detail.value
|
||||
this.setData({ searchQuery: e.detail.value }, () => {
|
||||
this.filterList();
|
||||
});
|
||||
},
|
||||
|
||||
setCategory(e) {
|
||||
this.setData({ activeCategory: e.currentTarget.dataset.cat }, () => {
|
||||
this.filterList();
|
||||
});
|
||||
},
|
||||
|
||||
filterList() {
|
||||
const { wikiList, searchQuery, activeCategory } = this.data;
|
||||
let result = wikiList;
|
||||
|
||||
if (searchQuery) {
|
||||
const q = searchQuery.toLowerCase();
|
||||
result = result.filter(item =>
|
||||
item.name.toLowerCase().includes(q) ||
|
||||
item.scientificName.toLowerCase().includes(q)
|
||||
);
|
||||
}
|
||||
|
||||
if (activeCategory !== '全部') {
|
||||
result = result.filter(item => item.category.includes(activeCategory));
|
||||
}
|
||||
|
||||
this.setData({ displayedList: result });
|
||||
},
|
||||
|
||||
goToDetail(e) {
|
||||
const item = e.currentTarget.dataset.item;
|
||||
wx.navigateTo({
|
||||
url: `/pages/plant-detail/index?id=${item.id}&mode=wiki`
|
||||
});
|
||||
},
|
||||
|
||||
openIdentifyModal() { this.setData({ showIdentifyModal: true }); },
|
||||
|
||||
onPopupVisibleChange(e) {
|
||||
this.setData({
|
||||
showIdentifyModal: e.detail.visible
|
||||
});
|
||||
},
|
||||
|
||||
closeIdentifyModal() { this.setData({ showIdentifyModal: false }); }
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"navigationBarTitleText": "植物百科",
|
||||
"usingComponents": {
|
||||
"t-search": "tdesign-miniprogram/search/search",
|
||||
"t-tag": "tdesign-miniprogram/tag/tag",
|
||||
"t-image": "tdesign-miniprogram/image/image",
|
||||
"t-fab": "tdesign-miniprogram/fab/fab",
|
||||
"t-popup": "tdesign-miniprogram/popup/popup",
|
||||
"t-cell": "tdesign-miniprogram/cell/cell",
|
||||
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group",
|
||||
"t-icon": "tdesign-miniprogram/icon/icon"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<!--pages/wiki/index.wxml-->
|
||||
<view class="wiki-page">
|
||||
|
||||
<view class="wiki-scroll-area">
|
||||
<view class="search-section">
|
||||
<t-search placeholder="搜索植物名称,如:龟背竹" value="{{searchQuery}}" bind:change="onSearchInput" shape="round" />
|
||||
</view>
|
||||
|
||||
<view class="category-scroll">
|
||||
<t-tag
|
||||
wx:for="{{['全部', '观叶', '观花', '多肉']}}"
|
||||
wx:key="*this"
|
||||
variant="{{activeCategory === item ? 'dark' : 'outline'}}"
|
||||
theme="{{activeCategory === item ? 'primary' : 'default'}}"
|
||||
shape="mark"
|
||||
size="medium"
|
||||
style="margin-right: 16rpx;"
|
||||
bind:tap="setCategory"
|
||||
data-cat="{{item}}"
|
||||
>
|
||||
{{item}}
|
||||
</t-tag>
|
||||
</view>
|
||||
|
||||
<view class="wiki-list">
|
||||
<view wx:for="{{displayedList}}" wx:key="id" class="wiki-card" bindtap="goToDetail" data-item="{{item}}">
|
||||
<view class="wiki-image">
|
||||
<t-image src="/assets/{{item.images[0]}}" mode="aspectFill" width="100%" height="100%" />
|
||||
</view>
|
||||
<view class="wiki-info">
|
||||
<view class="wiki-top">
|
||||
<text class="wiki-name">{{item.name}}</text>
|
||||
<text class="scientific-name">{{item.scientificName}}</text>
|
||||
</view>
|
||||
<t-tag size="small" variant="light" theme="success">{{item.category}}</t-tag>
|
||||
</view>
|
||||
<t-icon name="chevron-right" size="48rpx" color="#ccc" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Spacer -->
|
||||
<view style="height: 160rpx;"></view>
|
||||
</view>
|
||||
|
||||
<t-fab icon="scan" text="植物识别" bind:click="openIdentifyModal" aria-label="植物识别"></t-fab>
|
||||
|
||||
<!-- Identify Popup -->
|
||||
<t-popup visible="{{showIdentifyModal}}" bind:visible-change="onPopupVisibleChange" placement="bottom">
|
||||
<view class="popup-content">
|
||||
<view class="popup-header">
|
||||
<text class="popup-title">识别植物</text>
|
||||
</view>
|
||||
|
||||
<view class="upload-options-grid">
|
||||
<view class="upload-opt-item">
|
||||
<view class="opt-icon-circle" style="background: #E8F5E9;">
|
||||
<t-icon name="camera" size="64rpx" color="#2E7D32" />
|
||||
</view>
|
||||
<text>拍照识别</text>
|
||||
</view>
|
||||
<view class="upload-opt-item">
|
||||
<view class="opt-icon-circle" style="background: #E3F2FD;">
|
||||
<t-icon name="image" size="64rpx" color="#1565C0" />
|
||||
</view>
|
||||
<text>从相册上传</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="popup-footer">
|
||||
<t-button block variant="outline" bind:tap="closeIdentifyModal">取消</t-button>
|
||||
</view>
|
||||
</view>
|
||||
</t-popup>
|
||||
</view>
|
||||
@@ -0,0 +1,98 @@
|
||||
/** pages/wiki/index.wxss **/
|
||||
.wiki-page {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #F9FAFB;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.wiki-scroll-area {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 20rpx 40rpx;
|
||||
}
|
||||
|
||||
.search-section {
|
||||
margin-bottom: 32rpx;
|
||||
}
|
||||
|
||||
.category-scroll {
|
||||
display: flex;
|
||||
flex-wrap: wrap; /* TDesign Tags might wrap nicely */
|
||||
margin-bottom: 48rpx;
|
||||
}
|
||||
|
||||
/* Old chips removed, replaced by t-tag */
|
||||
|
||||
.wiki-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 32rpx;
|
||||
}
|
||||
|
||||
.wiki-card {
|
||||
background: white;
|
||||
padding: 32rpx;
|
||||
border-radius: 48rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 36rpx;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.03);
|
||||
}
|
||||
|
||||
.wiki-image {
|
||||
width: 140rpx; height: 140rpx;
|
||||
border-radius: 36rpx;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 8rpx 20rpx rgba(0,0,0,0.1);
|
||||
flex-shrink: 0;
|
||||
background: #f0f0f0;
|
||||
}
|
||||
.wiki-image t-image { width: 100%; height: 100%; display: block; }
|
||||
|
||||
.wiki-info { flex: 1; }
|
||||
|
||||
.wiki-top { margin-bottom: 8rpx; }
|
||||
.wiki-name { font-size: 34rpx; font-weight: 700; color: var(--text-main); display: block; margin-bottom: 4rpx; }
|
||||
.scientific-name { font-size: 24rpx; color: #90A4AE; font-style: italic; font-family: serif; display: block; }
|
||||
|
||||
|
||||
/* Popup Styles */
|
||||
.popup-content {
|
||||
background: white;
|
||||
border-radius: 40rpx 40rpx 0 0;
|
||||
padding: 40rpx;
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
|
||||
.popup-header {
|
||||
text-align: center;
|
||||
margin-bottom: 48rpx;
|
||||
}
|
||||
|
||||
.popup-title {
|
||||
font-size: 36rpx;
|
||||
font-weight: 800;
|
||||
color: var(--text-main);
|
||||
}
|
||||
|
||||
.upload-options-grid {
|
||||
display: flex; gap: 40rpx; justify-content: center;
|
||||
margin-bottom: 48rpx;
|
||||
}
|
||||
|
||||
.upload-opt-item {
|
||||
display: flex; flex-direction: column; align-items: center; gap: 16rpx;
|
||||
}
|
||||
|
||||
.opt-icon-circle {
|
||||
width: 120rpx; height: 120rpx; border-radius: 40rpx;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
}
|
||||
|
||||
.popup-footer {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
Reference in New Issue
Block a user