chengjie 4 月之前
父节点
当前提交
b88fd7959f

+ 80 - 0
components/alert-tip/alert-tip.js

@@ -0,0 +1,80 @@
1
+
2
+Component({
3
+  properties: {
4
+    // 提示内容
5
+    content: {
6
+      type: String,
7
+      value: ''
8
+    },
9
+    // 容器背景颜色
10
+    containerbgColor: {
11
+      type: String,
12
+      value: '#e3e3e3'
13
+    },
14
+    // 背景颜色
15
+    bgColor: {
16
+      type: String,
17
+      value: '#CA4B15'
18
+    },
19
+    // 文字颜色
20
+    textColor: {
21
+      type: String,
22
+      value: '#FFFFFF'
23
+    },
24
+    // 图标路径
25
+    iconPath: {
26
+      type: String,
27
+      value: '../../pages/images/sysIcon_b11.png'
28
+    },
29
+    // 显示时长(毫秒),显示多久后开始淡出
30
+    duration: {
31
+      type: Number,
32
+      value: 1000
33
+    },
34
+    // 淡出动画时长(毫秒)
35
+    fadeOutDuration: {
36
+      type: Number,
37
+      value: 1000
38
+    }
39
+  },
40
+
41
+  data: {
42
+    isShow: false,
43
+    alertClass: ''
44
+  },
45
+
46
+  methods: {
47
+    // 显示提示
48
+    showAlert: function(content) {
49
+      const that = this;
50
+      
51
+      // 如果传入了content参数,则更新content属性
52
+      if (content) {
53
+        this.setData({
54
+          content: content
55
+        });
56
+      }
57
+      
58
+      // 显示提示
59
+      this.setData({
60
+        isShow: true,
61
+        alertClass: ''
62
+      });
63
+      
64
+      // 设置定时器,显示一段时间后开始淡出
65
+      setTimeout(function() {
66
+        that.setData({
67
+          alertClass: 'alert-fadeout'
68
+        });
69
+        
70
+        // 淡出动画结束后,完全隐藏元素
71
+        setTimeout(function() {
72
+          that.setData({
73
+            isShow: false,
74
+            alertClass: ''
75
+          });
76
+        }, that.data.fadeOutDuration);
77
+      }, that.data.duration);
78
+    }
79
+  }
80
+});

+ 5 - 0
components/alert-tip/alert-tip.json

@@ -0,0 +1,5 @@
1
+
2
+{
3
+  "component": true,
4
+  "usingComponents": {}
5
+}

+ 6 - 0
components/alert-tip/alert-tip.wxml

@@ -0,0 +1,6 @@
1
+<view class="alert-container {{alertClass}} FlexRow" wx:if="{{isShow}}" style="background-color: {{containerbgColor}};">
2
+  <view class="alert-content FlexRow" style="background-color: {{bgColor}};">
3
+    <image src="{{iconPath}}" class="alert-icon"></image>
4
+    <view class="alert-text" style="color: {{textColor}};">{{content}}</view>
5
+  </view>
6
+</view>

+ 56 - 0
components/alert-tip/alert-tip.wxss

@@ -0,0 +1,56 @@
1
+
2
+
3
+.FlexColumn {
4
+  display: flex;
5
+  flex-direction: column;
6
+  align-items: center;
7
+  justify-content: center;
8
+}
9
+
10
+.FlexRow {
11
+  display: flex;
12
+  flex-direction: row;
13
+  align-items: center;
14
+  justify-content: center;
15
+}
16
+
17
+.alert-container {
18
+  position: fixed;
19
+  top: 0;
20
+  left:0;
21
+  width: 100%;
22
+  height: 100rpx;
23
+  z-index: 999;
24
+  justify-content: flex-start;
25
+  align-items: flex-start;
26
+}
27
+
28
+.alert-fadeout {
29
+  animation: fadeOut 1s ease-out forwards;
30
+}
31
+
32
+@keyframes fadeOut {
33
+  from {
34
+    opacity: 1;
35
+  }
36
+  to {
37
+    opacity: 0;
38
+  }
39
+}
40
+
41
+.alert-content {
42
+  border-radius: 10rpx;
43
+  height: 70rpx;
44
+  margin: 20rpx 0 0 30rpx;
45
+  padding: 0 30rpx;
46
+}
47
+
48
+.alert-icon {
49
+  width: 20rpx;
50
+  height: 20rpx;
51
+}
52
+
53
+.alert-text {
54
+  font-size: 24rpx;
55
+  margin-left: 20rpx;
56
+}

+ 99 - 0
docs/alert-tip-usage.md

@@ -0,0 +1,99 @@
1
+
2
+# AlertTip 组件使用说明
3
+
4
+这是一个用于显示顶部提示信息的自定义组件,支持自定义文本内容、背景颜色、显示时长和淡出动画。
5
+
6
+## 引入组件
7
+
8
+在需要使用组件的页面的 JSON 配置文件中引入组件:
9
+
10
+```json
11
+{
12
+  "usingComponents": {
13
+    "alert-tip": "../../components/alert-tip/alert-tip"
14
+  }
15
+}
16
+```
17
+
18
+## 在页面中使用组件
19
+
20
+在页面的 WXML 中添加组件:
21
+
22
+```html
23
+<alert-tip id="alertTip" 
24
+  container-bg-color="#E3E3E3" 
25
+  bg-color="#CA4B15" 
26
+  text-color="#FFFFFF" 
27
+  icon-path="../../pages/images/sysIcon_b11.png"
28
+  duration="1000"
29
+  fade-out-duration="1000">
30
+</alert-tip>
31
+```
32
+
33
+## 组件属性
34
+
35
+| 属性名 | 类型 | 默认值 | 说明 |
36
+|-------|------|-------|------|
37
+| content | String | '' | 提示内容 |
38
+| bgColor | String | '#CA4B15' | 背景颜色 |
39
+| textColor | String | '#FFFFFF' | 文字颜色 |
40
+| iconPath | String | '../../pages/images/sysIcon_b11.png' | 图标路径 |
41
+| duration | Number | 1000 | 显示时长(毫秒),显示多久后开始淡出 |
42
+| fadeOutDuration | Number | 1000 | 淡出动画时长(毫秒) |
43
+
44
+## 组件方法
45
+
46
+### showAlert(content)
47
+
48
+显示提示信息。
49
+
50
+**参数**
51
+
52
+- `content` (可选): 提示内容。如果提供,将覆盖组件的 content 属性。
53
+
54
+**示例**
55
+
56
+```javascript
57
+// 在页面的 JS 中调用组件的方法
58
+Page({
59
+  showTip: function() {
60
+    // 使用组件的默认 content
61
+    this.selectComponent('#alertTip').showAlert();
62
+    
63
+    // 或者提供新的 content
64
+    this.selectComponent('#alertTip').showAlert("这是一条提示信息");
65
+  }
66
+})
67
+```
68
+
69
+## 完整示例
70
+
71
+```javascript
72
+// 页面 JS
73
+Page({
74
+  data: {
75
+    // 页面数据
76
+  },
77
+  
78
+  onSomeAction: function() {
79
+    // 当某个条件满足时,显示提示
80
+    if (someCondition) {
81
+      this.selectComponent('#alertTip').showAlert("操作成功");
82
+    } else {
83
+      this.selectComponent('#alertTip').showAlert("操作失败");
84
+    }
85
+  }
86
+})
87
+```
88
+
89
+```html
90
+<!-- 页面 WXML -->
91
+<alert-tip id="alertTip" 
92
+  bg-color="#28a745" 
93
+  text-color="#FFFFFF">
94
+</alert-tip>
95
+
96
+<button bindtap="onSomeAction">执行操作</button>
97
+```
98
+
99
+这样,当用户点击按钮时,如果条件满足,将显示绿色背景的"操作成功"提示;否则显示"操作失败"提示。

+ 0 - 1
pages/main/myarticles.wxml

@@ -38,7 +38,6 @@
38 38
   <view style="height: 100rpx;"></view>
39 39
 </view>
40 40
 
41
-
42 41
 <view wx:if="{{IsShowRemind}}" class="panelRemindParent {{parentAnimation}} container FlexColumn" style='min-height:{{Containnerheight}}rpx;{{VectorCSS}}'>
43 42
   <view class="panelRemind {{panelAnimation}} FlexColumn">
44 43
     <image src="../images/sysIcon_b13.png" class="sysIcon_b10"></image>

+ 149 - 8
pages/main/mywords.js

@@ -1,12 +1,37 @@
1 1
 import common from '../../utils/util';
2 2
 import main from '../../utils/main';
3
+import animation from '../../utils/animation';
4
+
3 5
 const app = getApp();
4 6
 
5 7
 Page({
6 8
   data: {
7 9
     IsShowSelect:false,
10
+    IsShowRemind:false,
11
+    IsShowAlert:false,
12
+    AlertClass:"",
8 13
     Sort1:"panel112",
9 14
     Sort2:"",
15
+    RemindArr:[
16
+      {
17
+        "Title":"取消收藏",
18
+        "Content":"确定删除这条收藏记录吗?删除后无法恢复。",
19
+        "BtnName":"删除",
20
+      },{
21
+        "Title":"取消收藏",
22
+        "Content":"确定删除这些收藏记录吗?删除后无法恢复。",
23
+        "BtnName":"删除",
24
+      },{
25
+        "Title":"生成文章",
26
+        "Content":"要用这些单词生成新文章吗?",
27
+        "BtnName":"继续",
28
+      },{
29
+        "Title":"导出到秒过",
30
+        "Content":"要把这些单词做成秒过题卡吗?\n\n该功能需要切换到「秒过 - 错题记忆卡」小程序中实现。",
31
+        "BtnName":"继续",
32
+      },
33
+    ],
34
+    RemindIndex:0,
10 35
   },
11 36
   onLoad: function (options) {
12 37
     let that = this;
@@ -53,25 +78,141 @@ Page({
53 78
       if (list[i].Selected==1)
54 79
         count++;
55 80
     }
56
-    
81
+
57 82
     this.setData({
58 83
       List:list,
59 84
       Count:count, 
60 85
     });
61 86
   },
62 87
   setDataBoolean:function(e){
63
-    if (this.data.IsShowSelect){
64
-      let list=this.data.List;
65
-      for(let i=0;i<list.length;i++)
66
-        list[i].Selected=0;
67
-      this.setData({
68
-        List:list,
69
-      });
88
+    if (e.currentTarget.dataset.name=="IsShowSelect"){
89
+      this.cancelSelected();
70 90
     }
71 91
     this.setData({
72 92
       IsShowSelect:!this.data.IsShowSelect,
73 93
     });
74 94
   },
95
+  
96
+  showRemindStart:function(e){
97
+    let that=this;
98
+    let remindIndex=e.currentTarget.dataset.type;
99
+    this.setData({
100
+      RemindIndex:remindIndex,
101
+    });
102
+
103
+    let arr=that.getSelectedWord();
104
+    if (arr){
105
+      if (arr.length==0){
106
+        // 使用组件显示提示
107
+        this.selectComponent('#alertTip').showAlert("请至少选择1个单词");
108
+        return null;
109
+      }
110
+      else if (remindIndex==2 && arr.length>10){
111
+        // 使用组件显示提示
112
+        this.selectComponent('#alertTip').showAlert("一篇文章最多可选10个单词");
113
+        return null;
114
+      }
115
+    }
116
+
117
+    if (e.currentTarget.dataset.word)
118
+      that.Word=e.currentTarget.dataset.word;
119
+    animation.toggleRemindWithAnimation(this, {
120
+      hideColor: 'rgba(0,0,0,0)',
121
+      showColor: 'rgba(277,277,277,0.5)',
122
+      panelAnimationKey: 'panelAnimation', // 控制内容面板的动画
123
+      animationKey: 'parentAnimation' // 控制父容器的动画(如果需要)
124
+    });
125
+  },
126
+  showRemindEnd:function(e){
127
+    let that=this;
128
+    const confirm=e.currentTarget.dataset.confirm;
129
+    animation.toggleRemindWithAnimation(this, {
130
+      hideColor: 'rgba(0,0,0,0)',
131
+      showColor: 'rgba(277,277,277,0.5)'
132
+    });
133
+    if (confirm=="1") {
134
+      switch(Number(that.data.RemindIndex)){
135
+        case 0:
136
+          that.deleteItem(that.Word);
137
+          break;
138
+        case 1:
139
+          that.deleteMany();
140
+          break;
141
+        case 2:
142
+          that.setClipboard();
143
+          break;
144
+        case 3:
145
+          that.gotoMiaoguo();
146
+          break;
147
+      }
148
+    }
149
+  },
150
+  deleteItem:function(word){
151
+    let that=this;
152
+    main.getData('AddOrDeleteYJBDCUserCollect?UserID='+app.globalData.userInfo.UserID+'&Word='+word, function (data) {
153
+      if (data){
154
+        app.globalData.UserCollect=data;
155
+        that.setData({
156
+          List:app.globalData.UserCollect,
157
+        });
158
+        wx.showToast({
159
+          title: '删除完成',
160
+        });
161
+      }
162
+    });
163
+  },
164
+  deleteMany:function(){
165
+    let that=this;
166
+    let arr=that.getSelectedWord();
167
+    main.getData('DeleteYJBDCUserCollect?UserID='+app.globalData.userInfo.UserID+'&WordArr='+arr.join(","), function (data) {
168
+      if (data){
169
+        app.globalData.UserCollect=data;
170
+        that.setData({
171
+          List:app.globalData.UserCollect,
172
+        });
173
+        wx.showToast({
174
+          title: '批量删除完成',
175
+        });
176
+      }
177
+    });
178
+  },
179
+  setClipboard:function(e){
180
+    let that=this;
181
+    let arr=that.getSelectedWord(true);
182
+    app.globalData.SelectedWords=arr;
183
+    wx.redirectTo({
184
+      url: 'wordsinput',
185
+    });
186
+  },
187
+  gotoMiaoguo:function(e){
188
+    let that=this;
189
+    let arr=that.getSelectedWord();
190
+    var appid="wx84b3feac6069eec3";
191
+    var path="pages/index/index?SourceID="+app.globalData.ProgramID+"&goto=buildcard&Words="+arr.join(",");
192
+    wx.navigateToMiniProgram({
193
+      appId: appid,
194
+      path: path,
195
+    });
196
+  },
197
+  getSelectedWord:function(selectTen){
198
+    let that=this;
199
+    let list=that.data.List;
200
+    let arr=[];
201
+    for(let i=0;i<list.length;i++){
202
+      if (list[i].Selected==1)
203
+        arr.push(list[i].Word);
204
+    }
205
+    return arr;
206
+  },
207
+  cancelSelected:function(){
208
+    let list=this.data.List;
209
+    for(let i=0;i<list.length;i++)
210
+      list[i].Selected=0;
211
+    this.setData({
212
+      List:list,
213
+      Count:0, 
214
+    });
215
+  },
75 216
   goto: function (e) {
76 217
     let that=this;
77 218
     var url=e.currentTarget.dataset.url;

+ 5 - 1
pages/main/mywords.json

@@ -1,8 +1,12 @@
1
+
1 2
 {
2 3
   "navigationBarTitleText": "单词收藏",
3 4
   "navigationBarBackgroundColor": "#E3E3E3",
4 5
   "navigationBarTextStyle": "black",
5 6
   "backgroundColorTop":"#E3E3E3",
6 7
   "backgroundColorBottom":"#E3E3E3",
7
-  "backgroundColor": "#E3E3E3"
8
+  "backgroundColor": "#E3E3E3",
9
+  "usingComponents": {
10
+    "alert-tip": "../../components/alert-tip/alert-tip"
11
+  }
8 12
 }

+ 35 - 5
pages/main/mywords.wxml

@@ -9,6 +9,16 @@
9 9
     <view wx:if="{{IsShowSelect}}" class="panel12 FlexRow" bind:tap="setDataBoolean" data-name="IsShowSelect">取消</view>
10 10
   </view>
11 11
 
12
+  <alert-tip id="alertTip" 
13
+    container-bg-color="#E3E3E3" 
14
+    bg-color="#CA4B15" 
15
+    text-color="#FFFFFF" 
16
+    icon-path="../../pages/images/sysIcon_b11.png"
17
+    duration="2000"
18
+    fade-out-duration="2000">
19
+  </alert-tip>
20
+
21
+  <view style="height: 100rpx;"></view>
12 22
   <view class="panel2 FlexColumn">
13 23
     <view style="height: 20rpx;"></view>
14 24
     <view class="panel2Item FlexRow" wx:for="{{List}}" wx:key="index" bind:tap="selecItem" data-index="{{index}}">
@@ -20,7 +30,7 @@
20 30
       </view>
21 31
       <view class="panel2ItemLeft">{{item.Word}}</view>
22 32
       <view class="panel2ItemRight FlexRow" wx:if="{{!IsShowSelect}}">
23
-        <view class="panel2ItemRight1 FlexRow">
33
+        <view class="panel2ItemRight1 FlexRow" bind:tap="showRemindStart" data-type="0" data-word="{{item.Word}}">
24 34
           <image src="../images/sysIcon_a39.png" class="sysIcon_a39"></image>
25 35
         </view>
26 36
       </view>
@@ -31,22 +41,42 @@
31 41
 
32 42
   <view class="panelFooter FlexRow" wx:if="{{IsShowSelect}}">
33 43
     <view class="panelFooter1 FlexRow">
34
-      <view class="panelFooter11 panelFooter10 FlexColumn" bindtap="" >
44
+      <view class="panelFooter11 panelFooter10 FlexColumn" >
35 45
         <view class="text03">{{Count}}</view>
36 46
         <view class="text02">已选</view>
37 47
       </view>
38
-      <view class="panelFooter12 panelFooter10 FlexColumn" bindtap="" >
48
+      <view class="panelFooter12 panelFooter10 FlexColumn" catch:tap="showRemindStart" data-type="1" >
39 49
         <image src="../images/sysIcon_a14.png" class="sysIcon_a14"></image>
40 50
         <view class="text02">删除</view>
41 51
       </view>
42
-      <view class="panelFooter12 panelFooter10 FlexColumn" bindtap="" >
52
+      <view class="panelFooter12 panelFooter10 FlexColumn" catch:tap="showRemindStart" data-type="2"  >
43 53
         <image src="../images/sysIcon_a40.png" class="sysIcon_a14"></image>
44 54
         <view class="text02">生成文章</view>
45 55
       </view>
46
-      <view class="panelFooter13 panelFooter10 FlexColumn" bind:tap="">
56
+      <view class="panelFooter13 panelFooter10 FlexColumn" catch:tap="showRemindStart" data-type="3" >
47 57
         <image src="../images/sysIcon_a41.png" class="sysIcon_a14"></image>
48 58
         <view class="text02">导到秒过</view>
49 59
       </view>
50 60
     </view>
51 61
   </view>
62
+</view>
63
+
64
+<view wx:if="{{IsShowRemind}}" class="panelRemindParent {{parentAnimation}} container FlexColumn" style='min-height:{{Containnerheight}}rpx;{{VectorCSS}}'>
65
+  <view class="panelRemind {{panelAnimation}} FlexColumn">
66
+    <image src="../images/sysIcon_b13.png" class="sysIcon_b10"></image>
67
+      
68
+    <view class="panelRemind1 FlexRow">
69
+      <image src="../images/sysIcon_b12.png" class="sysIcon_b09"></image>
70
+      <view>{{RemindArr[RemindIndex].Title}}</view>
71
+    </view>
72
+    <view class="panelRemind2 FlexColumn">
73
+      <view class="textRemind FlexColumn">
74
+        <text>{{RemindArr[RemindIndex].Content}}</text>
75
+      </view>
76
+      <view class="panelRemind21 FlexColumn">
77
+        <view class="btnReind1 FlexColumn" catch:tap="showRemindEnd" data-confirm="1">{{RemindArr[RemindIndex].BtnName}}</view>
78
+        <view class="btnReind1 btnReind2 FlexColumn" catch:tap="showRemindEnd" data-confirm="0">取消</view>
79
+      </view>
80
+    </view>
81
+  </view>
52 82
 </view>

+ 71 - 1
pages/main/mywords.wxss

@@ -6,7 +6,10 @@
6 6
 .panel1 {
7 7
   width: 100%;
8 8
   height:100rpx;
9
-  position: relative;
9
+  position: fixed;
10
+  z-index: 10;
11
+  top:0;
12
+  background: #E3E3E3;
10 13
 }
11 14
 .panel11{
12 15
   width: 290rpx;
@@ -42,6 +45,10 @@
42 45
 .panel13{
43 46
   left:30rpx;
44 47
 }
48
+
49
+
50
+/* 提示相关样式已移至组件中 */
51
+
45 52
 .panel2{
46 53
   width: 690rpx;
47 54
   border-radius: 20rpx;
@@ -162,4 +169,67 @@
162 169
 .sysIcon_a14{
163 170
   width:20rpx;
164 171
   height:20rpx;
172
+}
173
+
174
+.panelRemind{
175
+  width: 690rpx;
176
+  margin-bottom: 75rpx;
177
+  position: fixed;
178
+  bottom: 0;
179
+
180
+  background: #FFA70C;
181
+  box-shadow: 0 20rpx 0 0 #CB8409, 0 50rpx 0 0 rgba(0,0,0,0.50);
182
+  border-radius: 60rpx;
183
+  background-image: radial-gradient(circle at 53% 50%, #85261E 0%, rgba(178,71,62,0.00) 50%);
184
+}
185
+.sysIcon_b10{
186
+  width: 360rpx;
187
+  height:140rpx;
188
+  position: absolute;
189
+  right:0;
190
+  top:-22rpx;
191
+}
192
+.panelRemind1{
193
+  width: 100%;
194
+  justify-content: flex-start;
195
+  margin-top: 40rpx;
196
+  font-size: 36rpx;
197
+  color: #FFFFFF;
198
+  z-index: 25rpx;
199
+}
200
+.sysIcon_b09{
201
+  width: 50rpx;
202
+  height:50rpx;
203
+  margin: 0 20rpx 0 50rpx ;
204
+}
205
+.panelRemind2{
206
+  width: 650rpx;
207
+  min-height:220rpx;
208
+  background: #FFFFFF;
209
+  color: #2E2E2E;
210
+  border-radius: 40rpx;
211
+  margin: 30rpx 0;
212
+  justify-content: flex-start;
213
+}
214
+.textRemind{
215
+  width:570rpx;
216
+  font-weight: 400;
217
+  font-size: 28rpx;
218
+  align-items: flex-start;
219
+  margin-top: 80rpx;
220
+}
221
+.panelRemind21{
222
+  width:100%;
223
+  margin: 60rpx 0 0 0;
224
+}
225
+.btnReind1{
226
+  width:580rpx;
227
+  height:90rpx;
228
+  background: #F0F0F0;
229
+  border-radius: 20rpx;
230
+  font-size: 36rpx;
231
+}
232
+
233
+.btnReind2{
234
+  margin: 30rpx 0 40rpx 0;
165 235
 }