| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- var field = "";
- var tempCursor = 0, btnName = "";
- var arrSoundMark = [];
- var isUnload = true;
- var isEdit = true;
- Page({
- data: {
- Field: "",
- SoundSign: "[读]",
- LineSign: "[线]",
- BtnArray: ["+", "-", "×", "÷", "="],
- },
- onLoad: function (options) {
- wx.hideShareMenu();
- var id = options.id;
- var fieldid = options.fieldid;
- field = "", tempCursor = 0, btnName = "", arrSoundMark = [];
- var that = this;
- that.setData({
- MiaoguoCardID: id,
- Focus: true,
- FieldNumber: fieldid,
- Containnerheight: main.getWindowHeight(),
- });
- wx.setNavigationBarTitle({
- title: '编辑 段落' + fieldid,
- });
- },
- onShow: function (e) {
- console.log("onShow:" + JSON.stringify(e));
- var that = this;
- if (isEdit) {
- var list = wx.getStorageSync("CardList");
- var card = {};
- for (var i = 0; i < list.length; i++) {
- if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- var content = main.encryptUrl(list[i].Content[this.data.FieldNumber].Content);
- this.setData({
- Field: content,
- });
- if (!wx.getStorageSync("TempCardInfoAddItem")) {
- wx.setStorageSync("TempCardInfoAddItem", content);
- }
- break;
- }
- }
- }
- isUnload = true;
- if (systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
- setTimeout(function () {
- isEdit = true;
- }, 600);
- }
- },
- onUnload: function () {
- if (isUnload) {
- var content = wx.getStorageSync("TempCardInfoAddItem");
- if (content != undefined) {
- this.updateField(content);
- wx.removeStorageSync("TempCardInfoAddItem");
- }
- }
- },
- bindinputField: function (e) {
- if (isEdit) {
- field = e.detail.value;
- this.setData({
- Field: e.detail.value,
- });
- console.log("bindinputField:" + field);
- }
- },
- addSymbol: function (e) {
- console.log("addSymbol");
- isEdit = true;
- var that = this;
- btnName = e.currentTarget.dataset.id;
- if (btnName == "[读]") {
- this.setData({
- SoundSign: "[/读]",
- });
- }
- else if (btnName == "[/读]") {
- this.setData({
- SoundSign: "[读]",
- });
- }
- else if (btnName == "[线]") {
- this.setData({
- LineSign: "[/线]",
- });
- }
- else if (btnName == "[/线]") {
- this.setData({
- LineSign: "[线]",
- });
- }
- if (!this.data.Focus) {
- field = field + btnName;
- this.setData({
- Field: field,
- });
- }
- //console.log("addSymbol:" + field);
- setTimeout(function () {
- that.setData({
- Focus: true,
- });
- }, 600);
- },
- onBindFocus: function () {
- this.setData({
- Focus: true,
- });
- },
- onBindblur: function (e) {
- var that = this;
- console.log("onBindblur:" + field + " btnName:" + btnName + " isEdit:" + isEdit);
- if (isEdit) {
- var systemInfo = wx.getSystemInfoSync();
- if (systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
- isEdit = false;
- }
- //console.log(e);
- tempCursor = e.detail.cursor;
- //console.log("tempCursor:" + tempCursor);
- if (tempCursor == undefined)
- tempCursor = this.data["Field"].length;
- var str1 = "", str2 = "";
- if (this.data.Field.length > 0) {
- str1 = this.data.Field.substr(0, tempCursor);
- str2 = this.data.Field.substring(tempCursor, this.data.Field.length);
- }
- //console.log("str1:" + str1);
- //console.log("str2:" + str2);
- var cur = 1;
- if (btnName == "[读]" || btnName == "[线]") {
- cur = 3;
- }
- else if (btnName == "[/读]" || btnName == "[/线]") {
- cur = 4;
- }
- field = str1 + btnName + str2;
- this.setData({
- Field: field,
- Focus: false,
- Cursor: tempCursor + cur,
- });
- btnName = "";
- if (systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
- setTimeout(function () {
- isEdit = true;
- }, 600);
- }
- }
- },
- onSearch: function (e) {
- wx.setStorageSync("TempFieldNumber", this.data.FieldNumber);
- wx.navigateTo({
- url: './searchWeb',
- });
- this.updateField();
- },
- clear: function () {
- console.log("clear");
- this.setData({
- Field: "",
- Focus: false,
- Cursor: 0,
- });
- btnName = "";
- field = "";
- isEdit = false;
- this.updateField();
- },
- closeAddItem: function (e) {
- var isSave = e.currentTarget.dataset.idsave;
- if (isSave == "true") {
- isUnload = false;
- wx.removeStorageSync("TempCardInfoAddItem");
- this.updateField();
- }
- wx.navigateBack({
- delta: 1,
- });
- },
- updateField: function (history) {
- var str = this.data.Field;
- str = main.decryptUrl(str);
- str = str.replace(/\[读\]/g, "\n[读]");
- str = str.replace(/\[图\]/g, "\n[图]");
- str = str.replace(/\[\/读\]/g, "[\/读]\n");
- str = str.replace(/\[\/图\]/g, "[\/图]\n");
- str = str.replace(/\n\n/g, "\n");
- var list = wx.getStorageSync("CardList");
- for (var i = 0; i < list.length; i++) {
- if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- if (history != undefined)
- list[i].Content[this.data.FieldNumber].Content = history;
- else
- list[i].Content[this.data.FieldNumber].Content = str;
- break;
- }
- }
- wx.setStorageSync("CardList", list);
- },
- uploadImage: function () {
- console.log("uploadImageStart");
- isEdit = false;
- var that = this;
- wx.chooseImage({
- count: 1,
- sizeType: ['compressed'],
- sourceType: ['album', 'camera'],
- success(res) {
- // tempFilePath可以作为img标签的src属性显示图片
- const tempFilePaths = res.tempFilePaths;
- //console.log(tempFilePaths[0]);
- field = field + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
- console.log("uploadImageEnd:" + field);
- that.setData({
- Field: field,
- Focus: false,
- });
- },
- fail: function () {
- }
- });
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|