chengjie hace 6 años
padre
commit
2e2664f0d6
Se han modificado 1 ficheros con 43 adiciones y 58 borrados
  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 4
 const app = getApp();
5 5
 
6
-var field = "";
7 6
 var tempCursor = 0, btnName = "";
8 7
 var arrSoundMark = [];
9
-var isUnload = true;
8
+var isUpload = true;
10 9
 
11 10
 var isEdit = true;
12 11
 
@@ -21,7 +20,8 @@ Page({
21 20
     wx.hideShareMenu();
22 21
     var id = options.id;
23 22
     var fieldid = options.fieldid;
24
-    field = "", tempCursor = 0, btnName = "", arrSoundMark = [];
23
+    tempCursor = 0, btnName = "", arrSoundMark = [];
24
+    isEdit=true;
25 25
 
26 26
     var that = this;
27 27
     that.setData({
@@ -34,10 +34,10 @@ Page({
34 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 39
     var that = this;
40
-    if (isEdit) {
40
+    if (isEdit){
41 41
       var list = wx.getStorageSync("CardList");
42 42
 
43 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 61
   onUnload: function () {
68
-    if (isUnload) {
62
+    if (isUpload) {
69 63
       var content = wx.getStorageSync("TempCardInfoAddItem");
70 64
       if (content != undefined) {
71 65
         this.updateField(content);
@@ -74,18 +68,15 @@ Page({
74 68
     }
75 69
   },
76 70
   bindinputField: function (e) {
71
+    console.log("bindinputField:" + isEdit);
77 72
     if (isEdit) {
78
-      field = e.detail.value;
79 73
       this.setData({
80 74
         Field: e.detail.value,
81 75
       });
82
-      console.log("bindinputField:" + field);
83 76
     }
84 77
   },
85 78
   addSymbol: function (e) {
86
-    console.log("addSymbol");
87
-    isEdit = true;
88
-    var that = this;
79
+    console.log("addSymbol:" + isEdit);
89 80
     btnName = e.currentTarget.dataset.id;
90 81
     if (btnName == "[读]") {
91 82
       this.setData({
@@ -106,35 +97,26 @@ Page({
106 97
       this.setData({
107 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 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 111
     this.setData({
127 112
       Focus: true,
128 113
     });
129 114
   },
130 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 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 121
       //console.log(e);
140 122
       tempCursor = e.detail.cursor;
@@ -156,20 +138,16 @@ Page({
156 138
         cur = 4;
157 139
       }
158 140
 
159
-      field = str1 + btnName + str2;
141
+      this.data.Field = str1 + btnName + str2;
160 142
       this.setData({
161
-        Field: field,
162
-        Focus: false,
143
+        Field: this.data.Field,
144
+        Focus:false,
163 145
         Cursor: tempCursor + cur,
164 146
       });
165 147
 
166 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 153
   onSearch: function (e) {
@@ -180,21 +158,18 @@ Page({
180 158
     this.updateField();
181 159
   },
182 160
   clear: function () {
183
-    console.log("clear");
161
+    console.log("clear:" + isEdit);
184 162
     this.setData({
185 163
       Field: "",
186 164
       Focus: false,
187 165
       Cursor: 0,
188 166
     });
189
-    btnName = "";
190
-    field = "";
191
-    isEdit = false;
192 167
     this.updateField();
193 168
   },
194 169
   closeAddItem: function (e) {
195 170
     var isSave = e.currentTarget.dataset.idsave;
196 171
     if (isSave == "true") {
197
-      isUnload = false;
172
+      isUpload = false;
198 173
       wx.removeStorageSync("TempCardInfoAddItem");
199 174
       this.updateField();
200 175
     }
@@ -225,9 +200,9 @@ Page({
225 200
     wx.setStorageSync("CardList", list);
226 201
   },
227 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 206
     wx.chooseImage({
232 207
       count: 1,
233 208
       sizeType: ['compressed'],
@@ -236,21 +211,31 @@ Page({
236 211
         // tempFilePath可以作为img标签的src属性显示图片
237 212
         const tempFilePaths = res.tempFilePaths;
238 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 219
         that.setData({
244
-          Field: field,
220
+          Field: that.data.Field,
245 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 239
   onShareAppMessage: function () {
255 240
     return {
256 241
       title: app.globalData.ShareTitle,