feat:绘制图形

This commit is contained in:
2025-09-12 16:56:00 +08:00
parent 3b4b2dcd64
commit 6acc5d676c
27 changed files with 76464 additions and 112 deletions
-7
View File
@@ -1,7 +0,0 @@
{
"navigationBarTitleText": "首页",
"navigationBarBackgroundColor": "#d2e7d8",
"homeButton": true,
"backgroundColor": "#e8eddb",
"enablePullDownRefresh": false
}
+183 -17
View File
@@ -3,31 +3,197 @@ page {
height: 100vh;
display: flex;
flex-direction: column;
background-color: #f5f5f5;
}
.container {
padding: 20rpx;
height: 100vh;
overflow-y: auto;
}
/* 输入区域样式 */
.input-section {
background-color: #fff;
border-radius: 20rpx;
padding: 30rpx;
margin-bottom: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.input-row {
display: flex;
align-items: center;
gap: 20rpx;
}
.word-input {
flex: 1;
height: 80rpx;
border: 2rpx solid #e0e0e0;
border-radius: 40rpx;
padding: 0 30rpx;
font-size: 32rpx;
background-color: #fafafa;
}
.generate-btn {
width: 160rpx;
height: 80rpx;
background-color: #07c160;
color: #fff;
border-radius: 40rpx;
font-size: 28rpx;
border: none;
display: flex;
align-items: center;
justify-content: center;
}
/* 通用区域样式 */
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20rpx;
}
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.clear-btn {
background-color: #ff4757;
color: #fff;
border-radius: 20rpx;
font-size: 24rpx;
padding: 10rpx 20rpx;
border: none;
}
/* 已选择的汉字区域 */
.selected-section {
background-color: #fff;
border-radius: 20rpx;
padding: 30rpx;
margin-bottom: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.word-list {
display: flex;
flex-wrap: wrap;
gap: 20rpx;
}
.word-item.selected {
background-color: #07c160;
color: #fff;
border-radius: 50rpx;
padding: 20rpx 30rpx;
position: relative;
min-width: 80rpx;
text-align: center;
}
.word-text {
font-size: 32rpx;
font-weight: bold;
}
.remove-btn {
position: absolute;
top: -10rpx;
right: -10rpx;
width: 40rpx;
height: 40rpx;
background-color: #ff4757;
color: #fff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 24rpx;
font-weight: bold;
cursor: pointer;
}
/* 可选汉字区域 */
.available-section {
background-color: #fff;
border-radius: 20rpx;
padding: 30rpx;
margin-bottom: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.word-grid {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 20rpx;
}
.word-item.available {
background-color: #f0f0f0;
color: #333;
border-radius: 50rpx;
padding: 20rpx;
text-align: center;
border: 2rpx solid #e0e0e0;
transition: all 0.3s ease;
}
.word-item.available:active {
background-color: #e0e0e0;
transform: scale(0.95);
}
.word-item.available.disabled {
background-color: #ccc;
color: #999;
cursor: not-allowed;
}
.word-item.available.disabled:active {
background-color: #ccc;
transform: none;
}
/* 功能模块区域 */
.cards-section {
background-color: #fff;
border-radius: 20rpx;
padding: 30rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.scroll-view {
flex: 1;
overflow-y: hidden;
height: 400rpx;
}
.card {
margin: 10px;
padding: 10px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: calc(33.33% - 20px);
/* Adjust width for three cards per row */
margin: 10rpx;
padding: 20rpx;
background-color: #f8f9fa;
border-radius: 20rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
width: calc(33.33% - 20rpx);
box-sizing: border-box;
/* Ensure padding and margin are included in the width */
display: inline-block;
/* Allow cards to sit next to each other */
vertical-align: top;
/* Align cards to the top */
transition: all 0.3s ease;
}
.card-title {
font-size: 18px;
font-weight: bold;
color: #333;
}
.card:active {
transform: scale(0.95);
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.2);
}
.card-title {
font-size: 28rpx;
font-weight: bold;
color: #333;
text-align: center;
}
+110
View File
@@ -1,5 +1,8 @@
Page({
data: {
inputWord: '', // 输入框中的汉字
wordList: [] as string[], // 选中的汉字列表
availableWords: [] as string[], // 从grade3.json中提取的前30个汉字
cards: [
{
key: 0,
@@ -24,6 +27,113 @@ Page({
],
},
onLoad() {
this.loadGrade3Words();
},
// 加载grade3.json中的前30个汉字
loadGrade3Words() {
const fs = wx.getFileSystemManager();
try {
const fileContent = fs.readFileSync('grade3.json', 'utf8') as string;
const grade3Data = JSON.parse(fileContent);
const words = Object.keys(grade3Data).slice(0, 30);
this.setData({
availableWords: words
});
} catch (error) {
console.error('加载grade3.json失败:', error);
// 如果文件读取失败,使用一些示例汉字
const fallbackWords = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '人', '口', '手', '足', '目', '耳', '鼻', '舌', '心', '肝', '脾', '肺', '肾', '胃', '肠', '胆', '膀', '胱', '皮', '毛'];
this.setData({
availableWords: fallbackWords
});
}
},
// 输入框输入事件
onInputChange(e: WechatMiniprogram.Input) {
this.setData({
inputWord: e.detail.value
});
},
// 生成按钮点击事件
onGenerateClick() {
const { inputWord, wordList } = this.data;
if (inputWord && inputWord.trim()) {
// 检查是否已经存在
if (!wordList.includes(inputWord.trim())) {
const newWordList = [...wordList, inputWord.trim()];
this.setData({
wordList: newWordList,
inputWord: '' // 清空输入框
});
wx.showToast({
title: '已添加到列表',
icon: 'success'
});
} else {
wx.showToast({
title: '该汉字已存在',
icon: 'none'
});
}
} else {
wx.showToast({
title: '请输入汉字',
icon: 'none'
});
}
},
// 选择汉字点击事件
onWordSelect(e: WechatMiniprogram.TouchEvent) {
const { word } = e.currentTarget.dataset;
const { wordList } = this.data;
if (!wordList.includes(word)) {
const newWordList = [...wordList, word];
this.setData({
wordList: newWordList
});
wx.showToast({
title: '已选择',
icon: 'success'
});
} else {
wx.showToast({
title: '已选择过',
icon: 'none'
});
}
},
// 从列表中移除汉字
onRemoveWord(e: WechatMiniprogram.TouchEvent) {
const { index } = e.currentTarget.dataset;
const { wordList } = this.data;
const newWordList = wordList.filter((_, i) => i !== index);
this.setData({
wordList: newWordList
});
wx.showToast({
title: '已移除',
icon: 'success'
});
},
// 清空所有选中的汉字
onClearAll() {
this.setData({
wordList: []
});
wx.showToast({
title: '已清空',
icon: 'success'
});
},
tapCard(e: WechatMiniprogram.TouchEvent) {
const { url } = e.currentTarget.dataset;
wx.navigateTo({ url });
+79 -10
View File
@@ -1,12 +1,81 @@
<!--index.wxml-->
<scroll-view class="scroll-view" scroll-y type="list">
<view
class="card"
wx:for="{{cards}}"
wx:for-item="card"
wx:key="*this"
bindtap="tapCard"
data-url="{{card.url}}">
<view class="card-title">{{card.title}}</view>
<view class="container">
<!-- 输入区域 -->
<view class="input-section">
<view class="input-row">
<input
class="word-input"
placeholder="请输入汉字"
value="{{inputWord}}"
bindinput="onInputChange"
maxlength="10" />
<button class="generate-btn" bindtap="onGenerateClick">生成</button>
</view>
</view>
</scroll-view>
<!-- 已选择的汉字列表 -->
<view class="selected-section" wx:if="{{wordList.length > 0}}">
<view class="section-header">
<text class="section-title"
>已选择的汉字 ({{wordList.length}})</text
>
<button class="clear-btn" bindtap="onClearAll" size="mini">
清空
</button>
</view>
<view class="word-list">
<view
class="word-item selected"
wx:for="{{wordList}}"
wx:key="*this"
wx:for-item="word"
wx:for-index="index">
<text class="word-text">{{word}}</text>
<text
class="remove-btn"
bindtap="onRemoveWord"
data-index="{{index}}"
>×</text
>
</view>
</view>
</view>
<!-- 可选汉字区域 -->
<view class="available-section">
<view class="section-header">
<text class="section-title"
>可选汉字 ({{availableWords.length}})</text
>
</view>
<view class="word-grid">
<view
class="word-item available {{wordList.includes(word) ? 'disabled' : ''}}"
wx:for="{{availableWords}}"
wx:key="*this"
wx:for-item="word"
bindtap="onWordSelect"
data-word="{{word}}">
<text class="word-text">{{word}}</text>
</view>
</view>
</view>
<!-- 原有的卡片区域 -->
<view class="cards-section">
<view class="section-header">
<text class="section-title">功能模块</text>
</view>
<scroll-view class="scroll-view" scroll-y type="list">
<view
class="card"
wx:for="{{cards}}"
wx:for-item="card"
wx:key="*this"
bindtap="tapCard"
data-url="{{card.url}}">
<view class="card-title">{{card.title}}</view>
</view>
</scroll-view>
</view>
</view>