chengjie 5 mesi fa
parent
commit
6b44f9311c

+ 2 - 4
app.json

@@ -1,16 +1,14 @@
1 1
 {
2 2
   "pages": [
3 3
     "pages/index/index",
4
+    "pages/main/help",
4 5
     "pages/main/myarticles",
5 6
     "pages/main/article",
6 7
     "pages/main/index",
7 8
     "pages/main/paste",
8 9
     "pages/main/ocr",
9 10
     "pages/main/selectword",
10
-    "pages/main/wordsinput",
11
-    "pages/logs/logs",
12
-    "pages/article_generator/article_generator",
13
-    "pages/ocr/ocr"
11
+    "pages/main/wordsinput"
14 12
   ],
15 13
   "window": {
16 14
     "backgroundTextStyle": "light",

+ 0 - 240
pages/article_generator/article_generator.js

@@ -1,240 +0,0 @@
1
-import common from '../../utils/util';
2
-import main from '../../utils/main';
3
-import constant1 from '../../utils/constant';
4
-
5
-Page({
6
-  data: {
7
-    wordList: [],
8
-    selectedWords: [],
9
-    difficulty: 0,
10
-    difficulties: constant1.arrHardLevel,
11
-    articleStyles: constant1.arrArticleStyle,
12
-    articleStyle: '',
13
-    generatedArticle: '',
14
-    articleTranslation: '',
15
-    generating: false,
16
-    Content:"",
17
-  },
18
-
19
-  onLoad: function(options) {
20
-    let that=this;
21
-    that.setData({
22
-      Containnerheight: main.getWindowHeight(),
23
-      IsShowTranslate:false,
24
-    });
25
-    let words=options.words;
26
-    if (!options.words)
27
-      words="boy,girl,king,come,go,yellow,dragon,fire";
28
-    if (words) {
29
-      try {
30
-        const wordList = words.split(",");
31
-        this.setData({ wordList });
32
-      } catch (e) {
33
-        wx.showToast({
34
-          title: '数据加载失败',
35
-          icon: 'none'
36
-        });
37
-      }
38
-    }
39
-  },
40
-
41
-  onDifficultyChange: function(e) {
42
-    this.setData({
43
-      difficulty: Number(e.detail.value)
44
-    });
45
-  },
46
-
47
-  onArticleStyleChange: function(e) {
48
-    this.setData({
49
-      articleStyle: e.detail.value
50
-    });
51
-    console.log('选择的文章类型:', e.detail.value);
52
-  },
53
-
54
-  generateArticle: async function() {
55
-    let that=this;
56
-
57
-    if (!this.data.articleStyle) {
58
-      wx.showToast({
59
-        title: '请选择文章类型',
60
-        icon: 'none'
61
-      });
62
-      return;
63
-    }
64
-
65
-    this.setData({ 
66
-      generating: true,
67
-      Content:"" 
68
-    });
69
-
70
-    try {
71
-      let url = common.Encrypt("GenerateArticle");
72
-      //url="https://www.kylx365.com/apiData/"+url;
73
-      url="http://localhost:3020/api/GenerateArticle";
74
-      let words=that.data.wordList;
75
-      const cloudRes = await new Promise((resolve, reject) => {
76
-        wx.request({
77
-          url: url,
78
-          method: "POST",
79
-          data: {
80
-            Words:JSON.stringify(words),
81
-            Level:that.data.difficulty,
82
-            Style:that.data.articleStyle
83
-          },
84
-          success: resolve,
85
-          fail: reject,
86
-        })
87
-      });
88
-      //console.log(cloudRes);
89
-      let result=cloudRes.data.result.choices[0].message.content;
90
-      console.log(result);
91
-      let content=JSON.parse(result);
92
-      //console.log(content);
93
-      for(let i=0;i<content.ArticleEnglish.length;i++){
94
-        for(let j=0;j<content.FormsOfWords.length;j++){
95
-          let word = content.FormsOfWords[j];
96
-          let regex = new RegExp(`\\b${word}\\b[.,!?;:]?`, 'gi');
97
-          content.ArticleEnglish[i] = content.ArticleEnglish[i].replace(regex, match => {
98
-            let punctuation = match.match(/[.,!?;:]$/);
99
-            let punc = punctuation ? punctuation[0] : '';
100
-            let wordPart = match.replace(/[.,!?;:]$/, '');
101
-            return `<span class='highlight'>${wordPart}</span>${punc}`;
102
-          });
103
-        }
104
-      }
105
-      content.ArticleEnglishStr=content.ArticleEnglish.join("");
106
-      for(let i=0;i<content.Question.length;i++){
107
-        for(let j=0;j<content.Question[i].OptionsEnglish.length;j++){
108
-          let str=content.Question[i].OptionsChinese[j];
109
-          content.Question[i].OptionsChinese[j]=str.substr(2);
110
-        }
111
-      }
112
-      this.setData({
113
-        Content:content,
114
-        generating: false
115
-      });
116
-    } catch (error) {
117
-      console.error('生成文章失败:', error);
118
-      wx.showToast({
119
-        title: '生成文章失败',
120
-        icon: 'none'
121
-      });
122
-      this.setData({ generating: false });
123
-    }
124
-  },
125
-
126
-  showTranslate:function(e){
127
-    this.setData({
128
-      IsShowTranslate:!this.data.IsShowTranslate,
129
-    })
130
-  },
131
-
132
-  generateTestArticle:function(e){
133
-    this.setData({
134
-      Content:{
135
-        Title: "Sample Reading Article",
136
-        ArticleEnglishStr:"This is a <span>sample</span> article for testing the PDF generation functionality.It contains multiple paragraphs and some <span>bold text</span> to test formatting.The PDF should be generated with proper layout and styling.",
137
-        ArticleEnglish: [
138
-          "This is a <span>sample</span> article for testing the PDF generation functionality.",
139
-          "It contains multiple paragraphs and some <span>bold text</span> to test formatting.",
140
-          "The PDF should be generated with proper layout and styling."
141
-        ],
142
-        Question: [
143
-          {
144
-            QuestionEnglish: "What is the purpose of this article?",
145
-            OptionsEnglish: [
146
-              "A. To test PDF generation",
147
-              "B. To teach English",
148
-              "C. To demonstrate formatting",
149
-              "D. All of the above"
150
-            ]
151
-          },
152
-          {
153
-            QuestionEnglish: "What special formatting is used in this article?",
154
-            OptionsEnglish: [
155
-              "A. Italics",
156
-              "B. Bold text",
157
-              "C. Underline",
158
-              "D. Strikethrough"
159
-            ]
160
-          }
161
-        ]
162
-      },
163
-    })
164
-  },
165
-
166
-  //生成PDF文件
167
-  //访问服务器的GeneratePDF接口,提交this.data.Content数据,获得一个生成好的pdf文件,服务端的代码已经生成好
168
-  generatePDF: function(e) {
169
-    let that = this;
170
-    this.setData({ 
171
-      generatingPDF: true,
172
-    });
173
-    
174
-    let url = common.Encrypt("GeneratePDF");
175
-    url = "https://www.kylx365.com/apiData/" + url;
176
-    //url="http://localhost:3020/api/GeneratePDF";
177
-    wx.request({
178
-      url: url,
179
-      method: "POST",
180
-      data: {
181
-        Content: that.data.Content
182
-      },
183
-      responseType: 'arraybuffer',  // 确保响应类型为arraybuffer
184
-      success: function(res) {
185
-        // 将arraybuffer转为临时文件
186
-        const fsm = wx.getFileSystemManager();
187
-        const tempFilePath = `${wx.env.USER_DATA_PATH}/temp_${Date.now()}.pdf`;
188
-        
189
-        try {
190
-          fsm.writeFileSync(
191
-            tempFilePath,
192
-            res.data,
193
-            'binary'
194
-          );
195
-
196
-          // 直接使用临时文件路径,不再尝试永久保存
197
-          console.log('文件已生成:', tempFilePath);
198
-          
199
-          // 打开PDF文件预览
200
-          wx.openDocument({
201
-            filePath: tempFilePath,
202
-            fileType: 'pdf',
203
-            showMenu: true,  // 显示右上角菜单,可以分享
204
-            success: function() {
205
-              console.log('打开文档成功');
206
-              wx.showToast({
207
-                title: 'PDF生成成功',
208
-                icon: 'success'
209
-              });
210
-            },
211
-            fail: function(error) {
212
-              console.error('打开文档失败:', error);
213
-              wx.showToast({
214
-                title: '打开文件失败',
215
-                icon: 'none'
216
-              });
217
-            }
218
-          });
219
-        } catch (error) {
220
-          console.error('写入文件失败:', error);
221
-          wx.showToast({
222
-            title: '写入文件失败',
223
-            icon: 'none'
224
-          });
225
-        }
226
-      },
227
-      fail: function(err) {
228
-        console.error('请求GeneratePDF接口失败:', err);
229
-        wx.showToast({
230
-          title: '网络错误,请稍候重试',
231
-          icon: 'none'
232
-        });
233
-      },
234
-      complete: function() {
235
-        that.setData({ generatingPDF: false });
236
-      }
237
-    });
238
-  },
239
-
240
-});

+ 0 - 5
pages/article_generator/article_generator.json

@@ -1,5 +0,0 @@
1
-
2
-{
3
-  "navigationBarTitleText": "AI文章生成",
4
-  "usingComponents": {}
5
-}

+ 0 - 107
pages/article_generator/article_generator.wxml

@@ -1,107 +0,0 @@
1
-<view class="container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
2
-
3
-  <view style="height: 30rpx;"></view>
4
-  <!-- 单词选择区域 -->
5
-  <view class="section">
6
-    <view class="section-title">需要生成的单词</view>
7
-    <view class="word-list">
8
-      <view 
9
-        wx:for="{{wordList}}" 
10
-        wx:key="*this" 
11
-        class="word-item"
12
-        data-word="{{item}}">
13
-        {{item}}
14
-      </view>
15
-    </view>
16
-  </view>
17
-
18
-  <!-- 难度选择区域 -->
19
-  <view class="section">
20
-    <view class="section-title">选择难度</view>
21
-    <radio-group class="difficulty-group" bindchange="onDifficultyChange">
22
-      <label class="difficulty-item" wx:for="{{difficulties}}" wx:key="value">
23
-        <radio value="{{item.Level}}" checked="{{difficulty === item.Level}}"/>
24
-        <text>{{item.Name}}</text>
25
-      </label>
26
-    </radio-group>
27
-  </view>
28
-
29
-  <!-- 文章类型选择区域 -->
30
-  <view class="section">
31
-    <view class="section-title">选择文章类型</view>
32
-    <radio-group class="two-column-layout" bindchange="onArticleStyleChange">
33
-      <block wx:for="{{articleStyles}}" wx:key="index" wx:for-item="category">
34
-        <view class="style-category">{{category.Name}}</view>
35
-        <view class="style-options-container">
36
-          <label class="style-option" 
37
-            wx:for="{{category.List}}" 
38
-            wx:key="Name"
39
-            wx:for-item="style">
40
-            <radio value="{{style.Name}}" checked="{{articleStyle === style.Name}}"/>
41
-            <text>{{style.Name}}</text>
42
-          </label>
43
-        </view>
44
-      </block>
45
-    </radio-group>
46
-  </view>
47
-
48
-  <!-- 生成按钮 -->
49
-  <view class="section">
50
-    <button 
51
-      class="generate-btn" 
52
-      type="primary" 
53
-      bindtap="generateArticle"
54
-      loading="{{generating}}">
55
-      生成文章
56
-    </button>
57
-
58
-    <button 
59
-      class="generate-btn" 
60
-      type="primary" 
61
-      bindtap="generateTestArticle">
62
-      测试文章(非AI生成)
63
-    </button>
64
-  </view>
65
-
66
-  <!-- 生成的文章区域 -->
67
-  <block wx:if="{{Content}}">
68
-    <view class="section" bind:tap="showTranslate">
69
-      <view class="section-title">生成的文章和阅读理解习题</view>
70
-      <view class="section-title1">点击文章可查看答案和逐句翻译</view>
71
-      <rich-text class="article-content" hidden="{{IsShowTranslate}}" nodes="{{Content.ArticleEnglishStr}}"></rich-text>
72
-      <view class="article-content FlexColumn" hidden="{{!IsShowTranslate}}">
73
-        <view wx:for="{{Content.ArticleEnglish}}" wx:key="index" class="translation-item">
74
-          <rich-text class="article-content1" nodes="{{item}}"></rich-text>
75
-          <view class="article-content2">{{Content.ArticleChinese[index]}}</view>
76
-        </view>
77
-      </view>
78
-      <view class="Question FlexColumn" wx:for="{{Content.Question}}" wx:key="index">
79
-        <text class="Question1">({{index+1}}) {{item.QuestionEnglish}}\r\n<text class="article-content2" wx:if="{{IsShowTranslate}}">{{item.QuestionChinese}}</text></text>
80
-        <text class="Options" wx:for="{{item.OptionsEnglish}}" wx:for-item="item2" wx:for-index="index2" wx:key="*this">
81
-          <text wx:if="{{!IsShowTranslate || !((item.Answer=='A' && index2==0) || (item.Answer=='B' && index2==1) || (item.Answer=='C' && index2==2) || (item.Answer=='D' && index2==3))}}">{{item2}}</text><text class="AnswerSelected" wx:if="{{((item.Answer=='A' && index2==0) || (item.Answer=='B' && index2==1) || (item.Answer=='C' && index2==2) || (item.Answer=='D' && index2==3)) && IsShowTranslate}}">{{item2}}</text>
82
-          <text class="article-content2" wx:if="{{IsShowTranslate}}">{{item.OptionsChinese[index2]}}</text>
83
-        </text>
84
-      </view>
85
-    </view>
86
-    <view class="section" wx:if="{{IsShowTranslate}}">
87
-      <view class="Answer FlexRow">
88
-        答案:<view class="Answer1" wx:for="{{Content.Question}}" wx:key="index">({{index+1}}) {{item.Answer}}</view>
89
-      </view>
90
-    </view>
91
-    <!-- 生成图片和PDF按钮 -->
92
-    <view class="section" wx:if="{{Content}}">
93
-      <view class="button-group">
94
-        <button 
95
-          class="generate-image-btn" 
96
-          bindtap="generatePDF"
97
-          loading="{{generatingPDF}}">
98
-          生成PDF文件
99
-        </button>
100
-      </view>
101
-    </view>
102
-  </block>
103
-
104
-  <!-- 用于生成图片的canvas,默认隐藏 -->
105
-  <canvas type="2d" id="articleCanvas" class="article-canvas" style="width: 595px; height: 842px;"></canvas>
106
-  <view style="height: 100rpx;"></view>
107
-</view>

+ 0 - 234
pages/article_generator/article_generator.wxss

@@ -1,234 +0,0 @@
1
-
2
-.container {
3
-  background-color: #fff;
4
-  color:#000;
5
-}
6
-
7
-.section {
8
-  margin-bottom: 30rpx;
9
-  background: #fff;
10
-  border-radius: 10rpx;
11
-  padding: 20rpx;
12
-  width: 650rpx;
13
-  box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
14
-}
15
-
16
-.section-title {
17
-  font-size: 32rpx;
18
-  font-weight: bold;
19
-  color: #333;
20
-  margin-bottom: 10rpx;
21
-}
22
-
23
-.section-title1 {
24
-  font-size: 24rpx;
25
-  font-weight: 400;
26
-  color: #999;
27
-  margin-bottom: 20rpx;
28
-}
29
-/* 单词列表样式 */
30
-.word-list {
31
-  display: flex;
32
-  flex-wrap: wrap;
33
-  gap: 20rpx;
34
-  margin-bottom: 20rpx;
35
-  width: 650rpx;
36
-}
37
-
38
-.word-item {
39
-  padding: 10rpx 20rpx;
40
-  background: #f5f5f5;
41
-  border-radius: 10rpx;
42
-  font-size: 28rpx;
43
-  color: #666;
44
-  border: 2rpx solid transparent;
45
-  transition: all 0.3s;
46
-}
47
-
48
-.word-item.selected {
49
-  background: #e6f3ff;
50
-  color: #0066cc;
51
-  border-color: #0066cc;
52
-}
53
-
54
-.selected-count {
55
-  font-size: 28rpx;
56
-  color: #666;
57
-  text-align: right;
58
-}
59
-
60
-/* 难度选择样式 */
61
-.difficulty-group {
62
-  display: flex;
63
-  flex-direction: column;
64
-  width: 650rpx;
65
-}
66
-
67
-.two-column-layout {
68
-  display: flex;
69
-  flex-direction: column;
70
-  width: 100%;
71
-}
72
-
73
-.style-options-container {
74
-  display: flex;
75
-  flex-wrap: wrap;
76
-  width: 100%;
77
-  gap: 10rpx;
78
-}
79
-
80
-.difficulty-item {
81
-  display: flex;
82
-  align-items: center;
83
-  gap: 10rpx;
84
-  font-size: 28rpx;
85
-  color: #333;
86
-  width: calc(50% - 10rpx);
87
-  box-sizing: border-box;
88
-  padding: 10rpx;
89
-}
90
-
91
-.style-option{
92
-  font-size:28rpx;
93
-}
94
-
95
-.full-width {
96
-  width: 100% !important;
97
-}
98
-
99
-/* 生成按钮样式 */
100
-.generate-btn {
101
-  width: 100% !important;
102
-  margin-top: 20rpx;
103
-}
104
-
105
-/* 文章区域样式 */
106
-.article-content {
107
-  font-size: 36rpx;
108
-  line-height: 1.6;
109
-  margin-bottom: 40rpx;
110
-  border-radius: 8rpx;
111
-  width: 650rpx;
112
-}
113
-
114
-.translation-item {
115
-  margin-bottom: 20rpx;
116
-  padding: 10rpx 0;
117
-  border-bottom: 1rpx solid #f0f0f0;
118
-  width: 100%;
119
-}
120
-
121
-.article-content1 {
122
-  margin-bottom: 8rpx;
123
-  color: #333;
124
-  width: 100%;
125
-  display: block;
126
-}
127
-
128
-.article-content2 {
129
-  color: #666;
130
-  font-size: 28rpx;
131
-  padding-left: 20rpx;
132
-  border-left: 4rpx solid #1890ff;
133
-  margin-top: 8rpx;
134
-  width: calc(100% - 24rpx);
135
-  display: block;
136
-}
137
-
138
-.AnswerSelected{
139
-  background-color: #27AE60;
140
-  color:#fff;
141
-}
142
-.Question{
143
-  width:90%;
144
-  margin: 30rpx 0;
145
-  align-items: flex-start;
146
-}
147
-.Question1{
148
-  font-size:36rpx;
149
-  font-weight: 700;
150
-}
151
-.Options{
152
-  font-size:32rpx;
153
-  margin: 15rpx 0;
154
-}
155
-.Answer{
156
-  width:650rpx;
157
-  justify-content: flex-start;
158
-}
159
-.Answer1{
160
-  width:80rpx;
161
-  margin: 0 10rpx;
162
-}
163
-.highlight{
164
-  color: #1890ff; 
165
-  font-weight: bold;
166
-}
167
-
168
-.article-canvas {
169
-  position: fixed;
170
-  left: -9999px;
171
-  visibility: hidden;
172
-}
173
-
174
-/* 按钮组样式 */
175
-.button-group {
176
-  display: flex;
177
-  justify-content: space-between;
178
-  gap: 20rpx;
179
-  width: 100%;
180
-  padding: 0 20rpx;
181
-  box-sizing: border-box;
182
-}
183
-
184
-.generate-image-btn {
185
-  flex: 1;
186
-  margin: 30rpx 0 !important;
187
-  background-color: #1890ff;
188
-  color: #fff;
189
-  font-size: 36rpx;
190
-  padding: 0 10rpx;
191
-  line-height: 80rpx;
192
-}
193
-
194
-/* 文章类型选择样式 */
195
-.style-category {
196
-  width: 100%;
197
-  font-size: 28rpx;
198
-  color: #666;
199
-  padding: 10rpx 0;
200
-  margin-top: 20rpx;
201
-  margin-bottom: 10rpx;
202
-  font-weight: bold;
203
-  border-bottom: 1rpx solid #eee;
204
-}
205
-
206
-.difficulty-group radio-group {
207
-  display: flex;
208
-  flex-wrap: wrap;
209
-  width: 100%;
210
-}
211
-
212
-.difficulty-item {
213
-  width: 50%;
214
-  box-sizing: border-box;
215
-  padding: 10rpx;
216
-}
217
-
218
-.difficulty-item radio {
219
-  transform: scale(0.8);
220
-}
221
-
222
-.difficulty-item text {
223
-  font-size: 28rpx;
224
-  color: #333;
225
-}
226
-
227
-/* 难度选择保持单列 */
228
-.difficulty-select radio-group {
229
-  flex-direction: column;
230
-}
231
-
232
-.difficulty-select .difficulty-item {
233
-  width: 100%;
234
-}

+ 0 - 20
pages/logs/logs.js

@@ -1,20 +0,0 @@
1
-// logs.js
2
-const util = require('../../utils/util.js')
3
-
4
-Component({
5
-  data: {
6
-    logs: []
7
-  },
8
-  lifetimes: {
9
-    attached() {
10
-      this.setData({
11
-        logs: (wx.getStorageSync('logs') || []).map(log => {
12
-          return {
13
-            date: util.formatTime(new Date(log)),
14
-            timeStamp: log
15
-          }
16
-        })
17
-      })
18
-    }
19
-  },
20
-})

+ 0 - 5
pages/logs/logs.json

@@ -1,5 +0,0 @@
1
-{
2
-  "usingComponents": {
3
-    "navigation-bar": "/components/navigation-bar/navigation-bar"
4
-  }
5
-}

+ 0 - 7
pages/logs/logs.wxml

@@ -1,7 +0,0 @@
1
-<!--logs.wxml-->
2
-<navigation-bar title="查看启动日志" back="{{true}}" color="black" background="#FFF"></navigation-bar>
3
-<scroll-view class="scrollarea" scroll-y type="list">
4
-  <block wx:for="{{logs}}" wx:key="timeStamp" wx:for-item="log">
5
-    <view class="log-item">{{index + 1}}. {{log.date}}</view>
6
-  </block>
7
-</scroll-view>

+ 0 - 16
pages/logs/logs.wxss

@@ -1,16 +0,0 @@
1
-page {
2
-  height: 100vh;
3
-  display: flex;
4
-  flex-direction: column;
5
-}
6
-.scrollarea {
7
-  flex: 1;
8
-  overflow-y: hidden;
9
-}
10
-.log-item {
11
-  margin-top: 20rpx;
12
-  text-align: center;
13
-}
14
-.log-item:last-child {
15
-  padding-bottom: env(safe-area-inset-bottom);
16
-}

+ 22 - 0
pages/main/help.js

@@ -0,0 +1,22 @@
1
+import common from '../../utils/util';
2
+import main from '../../utils/main';
3
+
4
+const app = getApp();
5
+
6
+Page({
7
+  data: {
8
+  },
9
+  onLoad: function (options) {
10
+    var that = this;
11
+    that.setData({
12
+      Containnerheight: main.getWindowHeight(),
13
+    });
14
+  },
15
+  onShareAppMessage: function () {
16
+    return {
17
+      title: app.globalData.ShareTitle,
18
+      path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
19
+      imageUrl: app.globalData.ShareImage,
20
+    }
21
+  },
22
+})

+ 5 - 0
pages/main/help.json

@@ -0,0 +1,5 @@
1
+{
2
+  "backgroundColorTop":"#004433",
3
+  "backgroundColorBottom":"#004433",
4
+  "usingComponents": {}
5
+}

+ 4 - 0
pages/main/help.wxml

@@ -0,0 +1,4 @@
1
+<view class="container FlexColumn" style='min-height:{{Containnerheight}}rpx;' bindtap="onContainerTap">
2
+  <image mode="widthFix" src="../images/pic_h0{{item}}.png" class="pic_h04" wx:for="{{[4,5,6,7,8]}}" wx:key="index"></image>
3
+        
4
+</view>

+ 7 - 0
pages/main/help.wxss

@@ -0,0 +1,7 @@
1
+page{
2
+  background-color: #004433;
3
+}
4
+.pic_h04{
5
+  width:100%;
6
+  height:auto;
7
+}

+ 2 - 2
pages/main/index.wxml

@@ -14,9 +14,9 @@
14 14
     </view>
15 15
 
16 16
     <view class="panel3 FlexColumn">
17
-      <view class="panel31 FlexRow">
17
+      <view class="panel31 FlexRow" bind:tap="goto" data-url="help">
18 18
         <image src="../images/sysIcon_a01.png" class="sysIcon_a01"></image>
19
-        <view>提升用AI生成短文质量的技巧</view>
19
+        <view>如何提升AI生成内容的质量</view>
20 20
       </view>
21 21
       <view class="panelLine"></view>
22 22
       <view class="panel31 FlexRow">

+ 2 - 0
pages/main/paste.js

@@ -46,6 +46,8 @@ Page({
46 46
   },
47 47
   bindKeyInput:function(e){
48 48
     let words=e.detail.value;
49
+    if (typeof words === 'string' && words.indexOf(",")>0)
50
+      words = words.split(",").join("\n");
49 51
     this.setData({
50 52
       Words:words, 
51 53
     });

+ 1 - 0
pages/main/wordsinput.js

@@ -122,6 +122,7 @@ Page({
122 122
     });
123 123
   },
124 124
   showExample:function(){
125
+    
125 126
     this.setData({
126 127
       IsShowExample:!this.data.IsShowExample,
127 128
     });

+ 0 - 274
pages/ocr/ocr.js

@@ -1,274 +0,0 @@
1
-import common from '../../utils/util';
2
-import main from '../../utils/main';
3
-
4
-Page({
5
-  data: {
6
-    cameraActive: true,
7
-    imageUrl: '',
8
-    recognizedTexts: [],
9
-    showCanvas: false,
10
-    Count:0,
11
-  },
12
-  onLoad: function(options) {
13
-    let that=this;
14
-    that.setData({
15
-      englishWords: null,  // 存储提取的英语单词
16
-    });
17
-  },
18
-  // 提取英语单词的函数 - 增强版
19
-  extractEnglishWords(texts) {
20
-    console.group('英语单词提取');
21
-    const words = new Set();
22
-    
23
-    texts.forEach(item => {
24
-      const text = item.text;
25
-      console.log('处理文本:', text);
26
-      
27
-      // 改进的正则表达式,能更好处理中英文混合文本
28
-      const wordRegex = /(?:^|\s|[\u4e00-\u9fa5])([A-Za-z]{2,}(?:['’-][A-Za-z]+)*)(?=$|\s|[\u4e00-\u9fa5])/g;
29
-      
30
-      let match;
31
-      while ((match = wordRegex.exec(text)) !== null) {
32
-        const word = match[1];
33
-        console.log('匹配到单词:', word);
34
-        
35
-        // 验证单词有效性
36
-        if (/^[A-Za-z'’-]+$/.test(word)) {
37
-          const lowerWord = word.toLowerCase();
38
-          words.add(lowerWord);
39
-          console.log('添加单词:', lowerWord);
40
-        }
41
-      }
42
-    });
43
-    
44
-    //const result = Array.from(words).sort();
45
-    const result=Array.from(words);
46
-    console.log('提取结果:', result);
47
-    console.groupEnd();
48
-    return result;
49
-  },
50
-
51
-  // 拍照识别
52
-  takePhoto() {
53
-    const ctx = wx.createCameraContext()
54
-    ctx.takePhoto({
55
-      quality: 'high',
56
-      success: (res) => {
57
-        this.setData({
58
-          imageUrl: res.tempImagePath,
59
-          cameraActive: false,
60
-          showCanvas: true
61
-        })
62
-        this.performOCR(res.tempImagePath)
63
-      },
64
-      fail: (err) => {
65
-        console.error('拍照失败:', err)
66
-        wx.showToast({
67
-          title: '拍照失败,请重试',
68
-          icon: 'none'
69
-        })
70
-      }
71
-    })
72
-  },
73
-
74
-  // 从相册选择
75
-  chooseImage() {
76
-    wx.chooseMedia({
77
-      count: 1,
78
-      mediaType: ['image'],
79
-      sourceType: ['album'],
80
-      success: (res) => {
81
-        const tempFilePath = res.tempFiles[0].tempFilePath
82
-        this.setData({
83
-          imageUrl: tempFilePath,
84
-          cameraActive: false,
85
-          showCanvas: true
86
-        })
87
-        this.performOCR(tempFilePath)
88
-      },
89
-      fail: (err) => {
90
-        console.error('选择图片失败:', err)
91
-        wx.showToast({
92
-          title: '选择图片失败',
93
-          icon: 'none'
94
-        })
95
-      }
96
-    })
97
-  },
98
-
99
-  // 加强版的OCR识别方法
100
-  async performOCR(imagePath) {
101
-    if (!imagePath) {
102
-      console.error('图片路径无效')
103
-    }
104
-
105
-    wx.showLoading({ title: '识别中...', mask: true })
106
-
107
-    try {
108
-      // 1. 压缩图片
109
-      const compressed = await new Promise((resolve, reject) => {
110
-        wx.compressImage({
111
-          src: imagePath,
112
-          quality: 70,
113
-          success: resolve,
114
-          fail: () => resolve({ tempFilePath: imagePath })
115
-        })
116
-      })
117
-      //console.log("1");
118
-      // 2. 转换为base64
119
-      const fileRes = await new Promise((resolve, reject) => {
120
-        wx.getFileSystemManager().readFile({
121
-          filePath: compressed.tempFilePath,
122
-          encoding: 'base64',
123
-          success: resolve,
124
-          fail: reject
125
-        })
126
-      })
127
-      //console.log("2");
128
-      // 3. 调用云函数(添加超时处理)
129
-      let postData={ ImageBase64: `data:image/jpeg;base64,${fileRes.data}` };
130
-      
131
-      let url = common.Encrypt("OCRImageData");
132
-      url="https://www.kylx365.com/apiData/"+url;
133
-      //url="http://localhost:3020/api/OCRImageData";
134
-      //console.log("url:"+url);
135
-      const cloudRes = await new Promise((resolve, reject) => {
136
-        wx.request({
137
-          url: url,
138
-          method: "POST",
139
-          data: postData,
140
-          success: resolve,
141
-          fail: reject,
142
-        })
143
-      });
144
-      //console.log("3");
145
-
146
-      // 4. 验证返回结果
147
-      if (!cloudRes || !cloudRes.data.result) {
148
-        throw new Error('无效的响应格式')
149
-      }
150
-      //console.log("4");
151
-      if (!cloudRes.data.result) {
152
-        throw new Error(cloudRes.data.result.message || '识别服务返回空数据')
153
-      }
154
-
155
-      // 5. 处理识别结果
156
-      const texts = cloudRes.data.result.TextDetections.map(item => ({
157
-        text: item.DetectedText || '未识别到文字',
158
-        pos: this.convertPosition(item.ItemPolygon || { Points: [] })
159
-      })).filter(item => item.DetectedText !== '未识别到文字')
160
-
161
-      //console.log("5");
162
-
163
-      if (texts.length === 0) {
164
-        throw new Error('未识别到有效文字')
165
-      }
166
-
167
-      // 6.提取英文单词
168
-      const engTexts=this.extractEnglishWords(texts);
169
-
170
-      let arr=[];
171
-      for(var i=0;i<engTexts.length;i++){
172
-        let obj={};
173
-        obj.Word=engTexts[i];
174
-        obj.Selected=0;
175
-        arr.push(obj);
176
-      }
177
-
178
-      this.setData({ 
179
-        recognizedTexts: texts,
180
-        englishWords:arr,
181
-      })
182
-
183
-    } catch (err) {
184
-      console.error('OCR处理失败:', err)
185
-      wx.showToast({
186
-        title: err.message || '识别失败',
187
-        icon: 'none',
188
-        duration: 3000
189
-      })
190
-    } finally {
191
-      wx.hideLoading()
192
-    }
193
-  },
194
-
195
-  // 加强坐标转换
196
-  convertPosition(polygon) {
197
-    try {
198
-      const points = polygon.Points || []
199
-      if (points.length === 0) {
200
-        return { x: 50, y: 50, width: 200, height: 30 }
201
-      }
202
-
203
-      const xs = points.map(p => p.X || 0)
204
-      const ys = points.map(p => p.Y || 0)
205
-      return {
206
-        x: Math.min(...xs),
207
-        y: Math.min(...ys),
208
-        width: Math.max(...xs) - Math.min(...xs),
209
-        height: Math.max(...ys) - Math.min(...ys)
210
-      }
211
-    } catch (e) {
212
-      return { x: 50, y: 50, width: 200, height: 30 }
213
-    }
214
-  },
215
-
216
-  
217
-  // 重新拍照
218
-  retake() {
219
-    this.setData({
220
-      cameraActive: true,
221
-      imageUrl: '',
222
-      recognizedTexts: [],
223
-      showCanvas: false
224
-    })
225
-  },
226
-
227
-  // 选择单词
228
-  selectWord(e) {
229
-    let that=this;
230
-
231
-    let list=that.data.englishWords;
232
-    const text = e.currentTarget.dataset.text
233
-    if (!text) return;
234
-
235
-    for(let i=0;i<list.length;i++){
236
-      if (text.Word==list[i].Word){
237
-        list[i].Selected=list[i].Selected==1?0:1;
238
-      }
239
-    }
240
-    that.setData({
241
-      englishWords:that.data.englishWords,
242
-    });
243
-
244
-    let count=0;
245
-    for(let i=0;i<list.length;i++){
246
-      if (list[i].Selected==1){
247
-        count++;
248
-      }
249
-    }
250
-    if (count>10){
251
-      wx.showToast({
252
-        title: '最多10个单词',
253
-      })
254
-    }
255
-    that.setData({
256
-      Count:count,
257
-    });
258
-  },
259
-
260
-  // 跳转到文章生成页面
261
-  goToArticleGenerator() {
262
-    let that=this;
263
-    let words=[];
264
-    let list=that.data.englishWords;
265
-    for(let i=0;i<list.length;i++){
266
-      if (list[i].Selected==1){
267
-        words.push(list[i].Word);
268
-      }
269
-    }
270
-    wx.redirectTo({
271
-      url: '/pages/index/index?words=' + words.join(","),
272
-    });
273
-  }
274
-})

+ 0 - 7
pages/ocr/ocr.json

@@ -1,7 +0,0 @@
1
-
2
-{
3
-  "navigationBarTitleText": "文字识别",
4
-  "navigationBarBackgroundColor": "#07c160",
5
-  "navigationBarTextStyle": "white",
6
-  "usingComponents": {}
7
-}

+ 0 - 44
pages/ocr/ocr.wxml

@@ -1,44 +0,0 @@
1
-<view class="container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
2
-  <!-- 相机视图 -->
3
-  <view class="camera-container" wx:if="{{cameraActive}}">
4
-    <camera device-position="back" flash="auto" class="camera"></camera>
5
-    <view class="camera-controls">
6
-      <view class="btn-capture FlexRow" bindtap="chooseImage">从相册选择</view>
7
-      <view class="btn-capture btn-retake FlexRow" bindtap="takePhoto">拍照</view>
8
-    </view>
9
-  </view>
10
-
11
-  <!-- 识别结果视图 -->
12
-  <view class="result-container" wx:else>
13
-    
14
-    <!-- 识别文字列表 -->
15
-    <view class="text-list" >
16
-      <view class="Title FlexColumn"  wx:if="{{englishWords.length >0 }}">
17
-        <view>请选择图片中识别出来的英语单词</view>
18
-        <view class="Title1">已经选中 {{Count}} 个单词</view>
19
-      </view>
20
-      
21
-     
22
-      <!-- 英语单词标签页 -->
23
-      <view class="english-tab-content">
24
-        <view scroll-y class="text-scroll FlexRow">
25
-          <view wx:if="{{englishWords.length === 0}}" class="no-result">
26
-            未识别到英语单词
27
-          </view>
28
-          <view wx:for="{{englishWords}}" wx:key="index" class="text-item FlexRow" bindtap="selectWord" data-text="{{item}}">
29
-            <view class="text-content textSelected{{item.Selected}}">{{item.Word}}</view>
30
-          </view>
31
-        </view>
32
-        <view class="generate-article-btn" wx:if="{{englishWords.length > 0}}">
33
-          <button type="primary" bindtap="goToArticleGenerator" disabled="{{Count<5 || Count>10}}">确定</button>
34
-        </view>
35
-      </view>
36
-    </view>
37
-
38
-    <!-- 底部控制栏 -->
39
-    <view class="bottom-controls">
40
-      <button class="btn-capture btn-retake" bindtap="retake">重新拍照</button>
41
-    </view>
42
-   
43
-  </view>
44
-</view>

+ 0 - 162
pages/ocr/ocr.wxss

@@ -1,162 +0,0 @@
1
-
2
-.container {
3
-  width: 100%;
4
-  height: 100vh;
5
-  display: flex;
6
-  flex-direction: column;
7
-  background-color: #f8f8f8;
8
-}
9
-
10
-/* 相机样式 */
11
-.camera-container {
12
-  width: 100%;
13
-  height: 100%;
14
-  position: relative;
15
-}
16
-
17
-.camera {
18
-  width: 100%;
19
-  height: 100%;
20
-}
21
-
22
-.camera-controls {
23
-  position: absolute;
24
-  bottom: 40rpx;
25
-  left: 0;
26
-  right: 0;
27
-  display: flex;
28
-  justify-content: center;
29
-  align-items: center;
30
-}
31
-
32
-.btn-capture {
33
-  width: 280rpx;
34
-  height: 100rpx;
35
-  line-height: 100rpx;
36
-  background-color: #ffffff;
37
-  margin: 0 20rpx;
38
-  border-radius: 30rpx;
39
-}
40
-
41
-
42
-/* 结果视图样式 */
43
-.result-container {
44
-  width: 100%;
45
-  height: 100%;
46
-  display: flex;
47
-  flex-direction: column;
48
-}
49
-
50
-.image-container {
51
-  width: 100%;
52
-  height: 50%;
53
-  display: flex;
54
-  justify-content: center;
55
-  align-items: center;
56
-  background-color: #000;
57
-}
58
-
59
-.preview-image, .highlight-canvas {
60
-  width: 100%;
61
-  height: 100%;
62
-  object-fit: contain;
63
-}
64
-
65
-.text-list {
66
-  flex: 1;
67
-  width: 100%;
68
-  background-color: #fff;
69
-  border-top-left-radius: 20rpx;
70
-  border-top-right-radius: 20rpx;
71
-  margin-top: -20rpx;
72
-  padding: 20rpx;
73
-  box-sizing: border-box;
74
-  display: flex;
75
-  flex-direction: column;
76
-}
77
-
78
-.text-list-header {
79
-  font-size: 32rpx;
80
-  font-weight: bold;
81
-  padding: 20rpx 0;
82
-  border-bottom: 1rpx solid #eee;
83
-}
84
-
85
-.text-scroll {
86
-  flex-wrap: wrap;
87
-  width: 100%;
88
-}
89
-
90
-.no-result {
91
-  text-align: center;
92
-  color: #999;
93
-  padding: 40rpx 0;
94
-}
95
-
96
-.text-item {
97
-  border: 1rpx solid #f0f0f0;
98
-  margin: 10rpx;
99
-  padding: 5rpx 10rpx;
100
-  background-color: #eee;
101
-}
102
-
103
-.text-content {
104
-  font-size: 30rpx;
105
-  color: #333;
106
-  padding: 3rpx 5rpx;
107
-  line-height: 1.5;
108
-  border-radius: 10rpx;
109
-}
110
-
111
-.text-tip {
112
-  font-size: 24rpx;
113
-  color: #999;
114
-  margin-top: 10rpx;
115
-}
116
-
117
-.bottom-controls {
118
-  padding: 20rpx;
119
-  display: flex;
120
-  justify-content: center;
121
-}
122
-
123
-.btn-retake {
124
-  background-color: #07c160;
125
-  color:#fff;
126
-}
127
-
128
-.Title{
129
-  width: 650rpx;
130
-  height:100rpx;
131
-  font-size:36rpx;
132
-  justify-content: flex-start;
133
-  align-items: flex-start;
134
-  margin: 30rpx 0;
135
-}
136
-
137
-.Title1{
138
-  font-size:28rpx;
139
-  color:#1d1d1d;
140
-}
141
-
142
-/* 英语单词标签页内容样式 */
143
-.english-tab-content {
144
-  display: flex;
145
-  flex-direction: column;
146
-  height: 100%;
147
-}
148
-
149
-.generate-article-btn {
150
-  padding: 20rpx;
151
-  margin-top: 20rpx;
152
-}
153
-
154
-.generate-article-btn button {
155
-  width: 100%;
156
-  border-radius: 40rpx;
157
-}
158
-
159
-.textSelected1{
160
-  background-color: #07c160;
161
-  color:#fff;
162
-}

+ 1 - 1
project.config.json

@@ -20,7 +20,7 @@
20 20
       "outputPath": ""
21 21
     },
22 22
     "compileWorklet": false,
23
-    "uglifyFileName": false,
23
+    "uglifyFileName": true,
24 24
     "uploadWithSourceMap": true,
25 25
     "packNpmManually": false,
26 26
     "minifyWXSS": true,

+ 1 - 1
project.private.config.json

@@ -19,5 +19,5 @@
19 19
     "checkInvalidKey": true,
20 20
     "ignoreDevUnusedFiles": true
21 21
   },
22
-  "libVersion": "3.8.9"
22
+  "libVersion": "3.0.2"
23 23
 }