| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- 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;
- tempCursor = 0, btnName = "", arrSoundMark = [];
- var that = this;
- that.setData({
- MiaoguoCardID: id,
- Focus: true,
- FieldNumber: fieldid,
- Containnerheight: main.getWindowHeight(),
- });
- wx.setNavigationBarTitle({
- title: '编辑 段落' + fieldid,
- });
- },
- onShow: function () {
- console.log("onShow");
- var that = this;
- console.log("onShow:" + isEdit);
- if (app.globalData.IsAndroid && !isEdit) {
- return;
- }
- 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;
- },
- onUnload: function () {
- if (isUnload) {
- var content = wx.getStorageSync("TempCardInfoAddItem");
- if (content != undefined) {
- this.updateField(content);
- wx.removeStorageSync("TempCardInfoAddItem");
- }
- }
- isEdit = true;
- },
- bindinputField: function (e) {
- var that = this;
- if (app.globalData.IsAndroid && !isEdit) {
- return;
- }
- this.setData({
- Field: e.detail.value,
- });
- console.log("bindinputField:" + e.detail.value);
- //this.updateField();
- },
- 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) {
- this.data.Field = this.data.Field + btnName;
- this.setData({
- Field: this.data.Field,
- });
- }
- //console.log("addSymbol:" + this.data.Field);
- setTimeout(function () {
- that.setData({
- Focus: true,
- });
- }, 300);
- },
- onBindFocus: function () {
- this.setData({
- Focus: true,
- });
- },
- onBindblur: function (e) {
- var that = this;
- console.log("onBindblur:" + isEdit + " Filed:" + this.data.Field);
- if (app.globalData.IsAndroid && !isEdit) {
- setTimeout(function () {
- isEdit = true;
- }, 500);
- return;
- }
- isEdit = false;
- console.log("onBindblur:"+isEdit);
- this.updateField();
- 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;
- } else if (btnName == "( )") {
- cur = 7;
- } else if (btnName == "_____") {
- cur = 5;
- }
- this.data.Field = str1 + btnName + str2;
- this.setData({
- Field: this.data.Field,
- Focus: false,
- Cursor: tempCursor + cur,
- });
- btnName = "";
- },
- onSearch: function (e) {
-
- wx.setStorageSync("TempFieldNumber", this.data.FieldNumber);
- wx.navigateTo({
- url: './searchWeb',
- });
- this.updateField();
-
- setTimeout(function () {
- isEdit = true;
- console.log("onSearchEnd");
- }, 1000);
- },
- clear: function () {
- var that = this;
- console.log("clear");
- this.setData({
- Field: "",
- Focus: true,
- Cursor: 0,
- });
- btnName = "";
- 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,
- });
- },
- uploadImage: function () {
- console.log("uploadImageStart");
- 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]);
- //that.data.Field = that.data.Field + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
- if (tempCursor == undefined)
- tempCursor = that.data.Field.length;
- var str1 = "",
- str2 = "";
- if (that.data.Field.length > 0) {
- str1 = that.data.Field.substr(0, tempCursor);
- str2 = that.data.Field.substring(tempCursor, that.data.Field.length);
- }
- var str0 = "[图 url='" + tempFilePaths[0] + "'][/图]";
- that.data.Field = str1 + str0 + str2;
- console.log("uploadImageEnd:" + that.data.Field);
- that.setData({
- Field: that.data.Field,
- Focus: false,
- });
- that.updateField();
- },
- fail: function () {
- }
- });
- },
- 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);
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|