chengjie 6 年之前
父節點
當前提交
2e2664f0d6
共有 1 個文件被更改,包括 43 次插入58 次删除
  1. 43 58
      pages/main/addItem.js

+ 43 - 58
pages/main/addItem.js

@@ -3,10 +3,9 @@ import main from '../../utils/main';
3
 
3
 
4
 const app = getApp();
4
 const app = getApp();
5
 
5
 
6
-var field = "";
7
 var tempCursor = 0, btnName = "";
6
 var tempCursor = 0, btnName = "";
8
 var arrSoundMark = [];
7
 var arrSoundMark = [];
9
-var isUnload = true;
8
+var isUpload = true;
10
 
9
 
11
 var isEdit = true;
10
 var isEdit = true;
12
 
11
 
@@ -21,7 +20,8 @@ Page({
21
     wx.hideShareMenu();
20
     wx.hideShareMenu();
22
     var id = options.id;
21
     var id = options.id;
23
     var fieldid = options.fieldid;
22
     var fieldid = options.fieldid;
24
-    field = "", tempCursor = 0, btnName = "", arrSoundMark = [];
23
+    tempCursor = 0, btnName = "", arrSoundMark = [];
24
+    isEdit=true;
25
 
25
 
26
     var that = this;
26
     var that = this;
27
     that.setData({
27
     that.setData({
@@ -34,10 +34,10 @@ Page({
34
       title: '编辑 段落' + fieldid,
34
       title: '编辑 段落' + fieldid,
35
     });
35
     });
36
   },
36
   },
37
-  onShow: function (e) {
38
-    console.log("onShow:" + JSON.stringify(e));
37
+  onShow: function () {
38
+    console.log("onShow:"+isEdit);
39
     var that = this;
39
     var that = this;
40
-    if (isEdit) {
40
+    if (isEdit){
41
       var list = wx.getStorageSync("CardList");
41
       var list = wx.getStorageSync("CardList");
42
 
42
 
43
       var card = {};
43
       var card = {};
@@ -56,16 +56,10 @@ Page({
56
         }
56
         }
57
       }
57
       }
58
     }
58
     }
59
-    isUnload = true;
60
-
61
-    if (systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
62
-      setTimeout(function () {
63
-        isEdit = true;
64
-      }, 600);
65
-    }
59
+    isUpload = true;
66
   },
60
   },
67
   onUnload: function () {
61
   onUnload: function () {
68
-    if (isUnload) {
62
+    if (isUpload) {
69
       var content = wx.getStorageSync("TempCardInfoAddItem");
63
       var content = wx.getStorageSync("TempCardInfoAddItem");
70
       if (content != undefined) {
64
       if (content != undefined) {
71
         this.updateField(content);
65
         this.updateField(content);
@@ -74,18 +68,15 @@ Page({
74
     }
68
     }
75
   },
69
   },
76
   bindinputField: function (e) {
70
   bindinputField: function (e) {
71
+    console.log("bindinputField:" + isEdit);
77
     if (isEdit) {
72
     if (isEdit) {
78
-      field = e.detail.value;
79
       this.setData({
73
       this.setData({
80
         Field: e.detail.value,
74
         Field: e.detail.value,
81
       });
75
       });
82
-      console.log("bindinputField:" + field);
83
     }
76
     }
84
   },
77
   },
85
   addSymbol: function (e) {
78
   addSymbol: function (e) {
86
-    console.log("addSymbol");
87
-    isEdit = true;
88
-    var that = this;
79
+    console.log("addSymbol:" + isEdit);
89
     btnName = e.currentTarget.dataset.id;
80
     btnName = e.currentTarget.dataset.id;
90
     if (btnName == "[读]") {
81
     if (btnName == "[读]") {
91
       this.setData({
82
       this.setData({
@@ -106,35 +97,26 @@ Page({
106
       this.setData({
97
       this.setData({
107
         LineSign: "[线]",
98
         LineSign: "[线]",
108
       });
99
       });
109
-    }
100
+    } 
110
 
101
 
111
-    if (!this.data.Focus) {
112
-      field = field + btnName;
102
+    if (!this.data.Focus){
103
+      this.data.Field=this.data.Field+btnName;
113
       this.setData({
104
       this.setData({
114
-        Field: field,
105
+        Field: this.data.Field,
115
       });
106
       });
116
     }
107
     }
117
-    //console.log("addSymbol:" + field); 
118
-
119
-    setTimeout(function () {
120
-      that.setData({
121
-        Focus: true,
122
-      });
123
-    }, 600);
108
+    //console.log("addSymbol:" + this.data.Field);
124
   },
109
   },
125
-  onBindFocus: function () {
110
+  onBindFocus:function(){
126
     this.setData({
111
     this.setData({
127
       Focus: true,
112
       Focus: true,
128
     });
113
     });
129
   },
114
   },
130
   onBindblur: function (e) {
115
   onBindblur: function (e) {
131
-    var that = this;
132
-    console.log("onBindblur:" + field + " btnName:" + btnName + " isEdit:" + isEdit);
116
+    console.log("onBindblur:" + isEdit);
117
+    var that=this;
133
     if (isEdit) {
118
     if (isEdit) {
134
-      var systemInfo = wx.getSystemInfoSync();
135
-      if (systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
136
-        isEdit = false;
137
-      }
119
+      that.androidFunction();
138
 
120
 
139
       //console.log(e);
121
       //console.log(e);
140
       tempCursor = e.detail.cursor;
122
       tempCursor = e.detail.cursor;
@@ -156,20 +138,16 @@ Page({
156
         cur = 4;
138
         cur = 4;
157
       }
139
       }
158
 
140
 
159
-      field = str1 + btnName + str2;
141
+      this.data.Field = str1 + btnName + str2;
160
       this.setData({
142
       this.setData({
161
-        Field: field,
162
-        Focus: false,
143
+        Field: this.data.Field,
144
+        Focus:false,
163
         Cursor: tempCursor + cur,
145
         Cursor: tempCursor + cur,
164
       });
146
       });
165
 
147
 
166
       btnName = "";
148
       btnName = "";
167
 
149
 
168
-      if (systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
169
-        setTimeout(function () {
170
-          isEdit = true;
171
-        }, 600);
172
-      }
150
+      
173
     }
151
     }
174
   },
152
   },
175
   onSearch: function (e) {
153
   onSearch: function (e) {
@@ -180,21 +158,18 @@ Page({
180
     this.updateField();
158
     this.updateField();
181
   },
159
   },
182
   clear: function () {
160
   clear: function () {
183
-    console.log("clear");
161
+    console.log("clear:" + isEdit);
184
     this.setData({
162
     this.setData({
185
       Field: "",
163
       Field: "",
186
       Focus: false,
164
       Focus: false,
187
       Cursor: 0,
165
       Cursor: 0,
188
     });
166
     });
189
-    btnName = "";
190
-    field = "";
191
-    isEdit = false;
192
     this.updateField();
167
     this.updateField();
193
   },
168
   },
194
   closeAddItem: function (e) {
169
   closeAddItem: function (e) {
195
     var isSave = e.currentTarget.dataset.idsave;
170
     var isSave = e.currentTarget.dataset.idsave;
196
     if (isSave == "true") {
171
     if (isSave == "true") {
197
-      isUnload = false;
172
+      isUpload = false;
198
       wx.removeStorageSync("TempCardInfoAddItem");
173
       wx.removeStorageSync("TempCardInfoAddItem");
199
       this.updateField();
174
       this.updateField();
200
     }
175
     }
@@ -225,9 +200,9 @@ Page({
225
     wx.setStorageSync("CardList", list);
200
     wx.setStorageSync("CardList", list);
226
   },
201
   },
227
   uploadImage: function () {
202
   uploadImage: function () {
228
-    console.log("uploadImageStart");
229
-    isEdit = false;
230
-    var that = this;
203
+    console.log("uploadImage:" + isEdit);
204
+    var that=this;
205
+    that.androidFunction();
231
     wx.chooseImage({
206
     wx.chooseImage({
232
       count: 1,
207
       count: 1,
233
       sizeType: ['compressed'],
208
       sizeType: ['compressed'],
@@ -236,21 +211,31 @@ Page({
236
         // tempFilePath可以作为img标签的src属性显示图片
211
         // tempFilePath可以作为img标签的src属性显示图片
237
         const tempFilePaths = res.tempFilePaths;
212
         const tempFilePaths = res.tempFilePaths;
238
         //console.log(tempFilePaths[0]);
213
         //console.log(tempFilePaths[0]);
239
-        field = field + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
240
 
214
 
241
-        console.log("uploadImageEnd:" + field);
215
+        that.data.Field = that.data.Field + "[图 url='" + tempFilePaths[0] + "'][/图]";
216
+
217
+        //console.log("uploadImageEnd:" + that.data.Field);
242
 
218
 
243
         that.setData({
219
         that.setData({
244
-          Field: field,
220
+          Field: that.data.Field,
245
           Focus: false,
221
           Focus: false,
246
         });
222
         });
223
+        that.updateField();
247
 
224
 
248
       },
225
       },
249
-      fail: function () {
250
-
226
+      fail:function(){
251
       }
227
       }
252
     });
228
     });
253
   },
229
   },
230
+  androidFunction:function(){
231
+    isEdit=false;
232
+    var systemInfo = wx.getSystemInfoSync();
233
+    if (systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
234
+      setTimeout(function () {
235
+        isEdit = true;
236
+      }, 1000);
237
+    }
238
+  },
254
   onShareAppMessage: function () {
239
   onShareAppMessage: function () {
255
     return {
240
     return {
256
       title: app.globalData.ShareTitle,
241
       title: app.globalData.ShareTitle,