| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- var arrTag = [];
- var tempCursor = undefined,
- btnName = "";
- var arrSoundMark = [];
- var isUnload = true;
- var isEdit = true;
- var isSave = true;
- var interval;
- var timeoutUploadImage = 0;
- var intervalRecorder = 0; //录音计时器
- var recorderManager;
- var tempRecorderFile = "";
- var innerAudioContext;
- var isViolate = false; //是否是违禁词
- var isFirstAdd = true;//是第一个填加
- Page({
- data: {
- HiddenFieldEdit: true,
- FieldContent: "",
- SoundSign: "[读]",
- LineSign: "[线]",
- HighlighterSign: "[光]",
- IsPracticeTime: false,
- IsRecorder: false,
- IsIPhoneX: app.globalData.IsIPhoneX,
- IsTagShow:false,
- IsEditCardType:"",
- PageTitle:"新建题卡",
- InputHeight:315,
- },
- onReady: function () {
- recorderManager = wx.getRecorderManager();
- recorderManager.onStart(() => {
- console.log('recorder start')
- });
- recorderManager.onStop((res) => {
- console.log('recorder stop', res);
- tempRecorderFile = res.tempFilePath;
- });
- recorderManager.onError((err) => {});
- },
- //获取导航栏高度
- getBarInfo(e) {
- var h=e.detail.topBarHeight;
- h=h*2;
- this.setData({
- topBarHeight: h,
- })
- },
- onLoad: function (options) {
- var that = this;
- var fieldNumber = 0;
- if (options.fieldid)
- fieldNumber = options.fieldid;
- that.setData({
- Containnerheight: main.getWindowHeight(),
- UpdateType: options.type,
- MiaoguoCardID: options.id,
- FieldNumber: fieldNumber,
- IsShow: app.globalData.userInfo.IsShow,
- });
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- wx.setStorageSync("TempCardInfo", list[i]);
- break;
- }
- }
- app.globalData.TempFieldNumber = 0;
- app.globalData.TempMiaoguoCardID = that.data.MiaoguoCardID;
- isViolate = false;
- isFirstAdd = true;
- if (app.globalData.IsIPhoneX){
- that.setData({
- InputHeight: 480,
- });
- }
- },
- onShow: function () {
- var that = this;
- if (that.data.UpdateType == "add") {
- that.initAddCard();
- if (!that.data.PracticeCardType && !that.data.PracticeTimeStr){
- that.setData({
- PracticeCardType: "日常",
- PracticeTimeStr: "",
- });
- }
- } else {
- var card = {},
- content = "";
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- card = main.changeStringToView(list[i].Content);
- card.MiaoguoCardID = list[i].MiaoguoCardID;
- if (list[i].CardType)
- card.CardType=list[i].CardType;
- else if (that.data.CardType)
- card.CardType=that.data.CardType;
- else
- card.CardType=0;
- if (list[i].LimitTime)
- card.LimitTime=list[i].LimitTime;
- else if (that.data.LimitTime)
- card.LimitTime=that.data.LimitTime;
-
- if (that.data.FieldNumber && that.data.FieldNumber > 0)
- content = main.encryptUrl(list[i].Content[that.data.FieldNumber].Content);
- break;
- }
- }
- switch(Number(card.CardType)){
- case 0:
- card.CardTypeStr="日常";
- break;
- case 1:
- card.CardTypeStr="紧急";
- break;
- case -1:
- card.CardTypeStr="留白";
- break;
- }
- if (app.globalData.TempIsEditCardType==1 && that.data.IsEditCardType==""){
- app.globalData.TempIsEditCardType=0;
- that.setData({
- IsEditCardType:"_IsEditCardType",
- });
- }
- that.setData({
- MiaoguoCardID: card.MiaoguoCardID,
- LimitTime: common.formatTime(card.LimitTime),
- PracticeCardType: card.CardTypeStr,
- PracticeTimeStr: common.formatDateCHS(common.formatTime(card.LimitTime)),
- Field: card.Field,
- Tags: card.Tags,
- TagsStr: card.Tags.join("、"),
- FieldContent: content,
- CardType:card.CardType,
- });
- if (that.data.UpdateType != "add2") {
- that.setData({
- PageTitle: '编辑题卡',
- });
- }
- if (that.data.UpdateType == "edit3") {
- that.gotoAddItem({
- currentTarget: {
- dataset: {
- fieldid: that.data.FieldNumber
- }
- }
- });
- }
- }
- common.getStorageValue(that, "SymbolMain", app.globalData.SymbolMain, function () { });
- },
- onHide: function () {
- //用于恢复未保存的新题卡
- //console.log("onHide");
- var that = this;
- if (!that.data.HiddenFieldEdit) {
- that.updateField();
- }
- if (!(that.data && that.data.Field && that.data.Field[1].length == 0 &&
- that.data.Field[2].length == 0 &&
- that.data.Field[3].length == 0)) {
- if (!isViolate && (that.data.UpdateType == "add" || that.data.UpdateType == "add2")) {
- var card = {};
- card.MiaoguoCardID = that.data.MiaoguoCardID;
- card.Content = [];
- var param1 = {};
- param1 = that.formatField(that.data.Field);
- for (var i = 0; i < 4; i++) {
- var obj = {};
- obj.ContentType = i;
- if (i == 0)
- obj.Content = that.data.Tags;
- else
- obj.Content = param1["Field" + i];
- card.Content.push(obj);
- }
- wx.setStorageSync("TempCardNoSaved", card);
- }
- }
- },
- onUnload: function () {
- this.onHide();
- var card = wx.getStorageSync("TempCardInfo");
- if (card) {
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- list[i] = card;
- break;
- }
- }
- app.globalData.CardList = list;
- wx.removeStorageSync("TempCardInfo");
- }
- clearInterval(interval);
- clearTimeout(timeoutUploadImage);
- clearInterval(intervalRecorder);
- if (this.data.IsRecorder)
- this.closeRecorder();
- if (wx.getStorageSync("IsRemindContinuousNew")==1){
- wx.removeStorageSync('IsRemindContinuousNew');
- }
- },
- onClose: function () {
- wx.navigateBack({
- delta: 1,
- });
- clearInterval(intervalRecorder);
- },
- gotoAddItem: function (e) {
- var that = this;
- var fieldid = e.currentTarget.dataset.fieldid;
- var content;
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- content = main.encryptUrl(list[i].Content[fieldid].Content);
- break;
- }
- }
- wx.setStorageSync("TempCardInfoAddItem", content);
- that.setData({
- HiddenFieldEdit: false,
- Focus: true,
- FieldNumber: fieldid,
- FieldContent: content,
- });
-
- that.setData({
- PageTitle: '编辑 段落' + fieldid,
- });
- },
- onSearch: function (e) {
- app.globalData.TempFieldNumber = 0;
- wx.navigateTo({
- url: './searchWeb',
- })
- },
- onPreview: function (e) {
- var that = this;
- if (that.data.Field[1] == "") {
- wx.showToast({
- title: '填写段落1',
- image: "../images/universalpic_warning_white_126x120.png",
- });
- } else {
- wx.navigateTo({
- url: './preview?type=preview&id=' + this.data.MiaoguoCardID,
- });
- }
- },
- saveCard: function () {
- var that = this;
- if (that.data.Field[1] == "") {
- wx.showToast({
- title: '填写段落1',
- image: "../images/universalpic_warning_white_126x120.png",
- });
- } else {
- if (isSave) {
- isSave = false;
- setTimeout(function () {
- isSave = true;
- }, 5000);
- if (that.checkImageCount(that.data.Field)) {
- that.uploadImageAll(that.data.Field, function (success, field) {
- if (success) {
- that.data.Field = field;
- var userid = app.globalData.userInfo.UserID;
- var tags = [];
- for (var i = 0; i < that.data.Tags.length; i++) {
- if (that.data.Tags[i])
- tags.push(that.data.Tags[i]);
- }
- var param1 = {};
- param1 = that.formatField(that.data.Field);
- param1.Tags = tags;
-
- param1.LimitTime = that.data.LimitTime;
- if (!param1.LimitTime)
- param1.LimitTime=common.formatTime(new Date(),"-",true);
- param1.CardType = that.data.CardType;
- if (!param1.CardType)
- param1.CardType=0;
- param1.ID = that.data.MiaoguoCardID;
- that.saveLocalCardList(param1);
- wx.hideLoading();
- wx.showLoading({
- title: '保存中',
- mask: true,
- });
- timeoutUploadImage = setTimeout(function () {
- wx.hideLoading();
- }, 15000);
- main.postData('AddMiaoguoCard?Type=' + that.data.UpdateType + '&UserID=' + userid, param1, function (data) {
- wx.removeStorageSync("TempCardNoSaved");
- if (that.data.UpdateType == "edit" || that.data.UpdateType == "edit2" || that.data.UpdateType == "edit3") {
- that.onClose();
- } else {
- wx.hideLoading();
- if (that.data.UpdateType == "add2") {
- if (!wx.getStorageSync("IsRemindContinuousNew") && that.data.IsEditCardType){
- wx.showModal({
- title: '提醒',
- showCancel: true,
- cancelText: "不再提醒",
- content: '连续新建会保留上一张题卡的练习模式、到期时间等设置,以便减少设置次数,新建一批相同属性的题卡。以蓝色标明。点恢复按键可立即恢复成默认设置。',
- confirmText: '好的',
- success(res) {
- if (res.confirm) {
- wx.setStorageSync("IsRemindContinuousNew",1);
- }
- else{
- wx.setStorageSync("IsRemindContinuousNew",2);
- }
- }
- });
- }
- else{
- wx.showToast({
- title: '已保存',
- image: "../images/universalpic_saved_white_120x120.png",
- });
- }
- isFirstAdd = false;
- that.initAddCard();
- }
- else{
- wx.showToast({
- title: '已保存',
- image: "../images/universalpic_saved_white_120x120.png",
- });
- }
- }
- wx.removeStorageSync("TempCardInfo");
- if (that.data.CardType==1){
- var cardType=wx.getStorageSync('CardType');
- if (cardType==0 && app.globalData.TaskToday.CardNumberUrgent==1){
- wx.navigateTo({
- url: "../other/menu?Type=0",
- });
- }
- }
- });
- } else {
- wx.showToast({
- title: '图片上传失败1',
- mask: true,
- });
- }
- });
- }
- } else {
- wx.showToast({
- title: '点击太频繁',
- mask: true,
- });
- }
- }
- },
- formatField: function (field) {
- var result = {};
- for (var i = 1; i <= 3; i++) {
- result["Field" + i] = "";
- if (field.length>0 && field[i]) {
- for (var key in field[i]) {
- var item = field[i][key];
- var str = "";
- if (item.Type == "image") {
- str = "[图 w='" + item.Width + "' h='" + item.Height + "']" + item.Content + "[/图]";
- } else if (item.Type == "line") {
- for (var j = 0; j < item.Content.length; j++) {
- if (item.Content[j].key == "normal")
- str += item.Content[j].value;
- if (item.Content[j].key == "line") {
- str += "[线]" + item.Content[j].value + "[/线]";
- }
- if (item.Content[j].key == "highlighter") {
- str += "[光]" + item.Content[j].value + "[/光]";
- }
- }
- } else if (item.Type == "sound") {
- if (item.SoundMark)
- str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
- else
- str = "[读]" + item.Content + "[/读]";
- } else if (item.Type == "recorder") {
- if (item.SoundMark)
- str = "[音 url='" + item.SoundMark + "'][/音]";
- } else if (item.Type == "normal") {
- str = item.Content;
- } else if (item.Type == "return") {
- str = "\n";
- }
- result["Field" + i] += str;
- }
- }
- result["Field" + i] = main.changeViewToString(result["Field" + i]);
- }
- return result;
- },
- checkImageCount: function (arr) {
- var count = 0;
- for (var i = 0; i < arr.length; i++) {
- for (var j = 0; j < arr[i].length; j++) {
- if (arr[i][j].Type == "image" && arr[i][j].Content) {
- count++;
- }
- }
- }
- if (count > 3) {
- wx.showToast({
- title: '只能上传三张图片',
- });
- return false;
- } else
- return true;
- },
- uploadImageAll: function (arr, callback) {
- var that = this;
- var b = false;
- var arrSource = [],
- arrResult = [];
- for (var i = 0; i < arr.length; i++) {
- for (var j = 0; j < arr[i].length; j++) {
- if (arr[i][j].Type == "image" && arr[i][j].Content) {
- arrSource.push(arr[i][j].Content);
- if (arr[i][j].ContentServer.indexOf(app.globalData.uploadImageUrl) >= 0 ||
- arr[i][j].ContentServer.indexOf("baidu.com") >= 0 ||
- arr[i][j].ContentServer.indexOf("bcebos.com") >= 0) {
- var result = {};
- result.Source = arr[i][j].ContentServer;
- result.Target = arr[i][j].ContentServer;
- arrResult.push(result);
- } else {
- var source = arr[i][j].Content;
- that.uploadFileToServer(source, function (data) {
- if (data) {
- data = JSON.parse(data);
- var result = data.result;
- result.Target = app.globalData.uploadImageUrl + result.Target;
- arrResult.push(result);
- }
- });
- }
- b = true;
- }
- }
- }
- if (b) {
- wx.showLoading({
- title: '正在上传',
- mask: true,
- });
- timeoutUploadImage = setTimeout(function () {
- wx.hideLoading();
- }, 30000);
- }
- interval = setInterval(function () {
- //console.log(arrResult.length);
- if (arrResult.length >= arrSource.length) {
- wx.hideLoading();
- //console.log("arrResult:" + JSON.stringify(arrResult));
- clearInterval(interval);
- var success = true;
- var ari = 0;
- for (var i = 0; i < arr.length; i++) {
- for (var j = 0; j < arr[i].length; j++) {
- if (arr[i][j].Type == "image" && arr[i][j].Content) {
- var tempUrl = arr[i][j].Content;
- var serverUrl = "";
- for (var k = 0; k < arrResult.length; k++) {
- if (tempUrl.indexOf(arrResult[k].Source) >= 0) {
- serverUrl = arrResult[k].Target;
- break;
- }
- }
- //console.log("serverUrl:" + serverUrl);
- //console.log("tempUrl:" + tempUrl);
- if (serverUrl == "")
- serverUrl = main.getServerImage(tempUrl);
- main.saveTempImage(serverUrl, tempUrl);
- arr[i][j].Content = serverUrl;
- arr[i][j].ContentServer = serverUrl;
- if (serverUrl == "") {
- success = false;
- break;
- }
- }
- }
- }
- //console.log(JSON.stringify(arr));
- callback(success, arr);
- }
- }, 500);
- },
- uploadFileToServer: function (file, callback) {
- var url = common.Encrypt("MiaoguoUploadFile2");
- wx.uploadFile({
- url: app.globalData.serverUrl + url,
- filePath: file,
- name: 'file',
- success(res) {
- callback(res.data);
- },
- fail: function (err) {
- wx.hideLoading();
- wx.showModal({
- title: '上传文件失败',
- showCancel: false,
- content: JSON.stringify(err),
- });
- }
- });
- },
- saveLocalCardList: function (param1) {
- var that = this;
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- for (var j = 0; j < 4; j++) {
- if (j == 0) {
- if (param1.tags && param1.tags.length > 0)
- list[i].Content[j].Content = param1.tags.join(",");
- } else
- list[i].Content[j].Content = param1["Field" + j];
- }
- if (param1.LimitTime)
- list[i].LimitTime = common.formatTime(param1.LimitTime);
- if (param1.IsTodayStudy == 1) {
- list[i].LimitTime = common.formatTime(new Date());
- main.getTaskTodayList(function () { });
- }
- app.globalData.CardList = list;
- break;
- }
- }
- },
- initAddCard: function () {
- var card = {};
- card.MiaoguoCardID = 0;
- card.Content = [];
- for (var i = 0; i < 4; i++) {
- var obj = {};
- obj.ContentType = i;
- obj.Content = [];
- card.Content.push(obj);
- }
- app.globalData.CardList = [card];
- this.setData({
- MiaoguoCardID: 0,
- Field: [
- [],
- [],
- [],
- []
- ],
- Tags: [],
- UpdateType: "add2",
- });
- },
- onBindError: function (e) {
- for (var i = 1; i < this.data.Field.length; i++) {
- for (var j = 0; j < this.data.Field[i].length; j++) {
- if (this.data.Field[i][j].Type == "image") {
- this.data.Field[i][j].Url = this.data.Field[i][j].Content;
- }
- }
- }
- this.setData({
- Field: this.data.Field,
- });
- },
- deleteItem: function (e) {
- var that = this;
- var index = e.currentTarget.dataset.id;
- if (e.currentTarget.dataset.type==1){
- that.setData({
- TagIndex: index,
- });
- }
- else if (e.currentTarget.dataset.type==2){
- that.data.TagTemp.splice(index, 1);
- that.setData({
- TagTemp: that.data.TagTemp,
- TagIndex: -1,
- });
- }
- else if (e.currentTarget.dataset.type==3){
- that.setData({
- Tags: that.data.TagTemp,
- TagsStr:that.data.TagTemp.join("、"),
- TagIndex: -1,
- });
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- list[i].Content[0].Content = that.data.Tags;
- break;
- }
- }
- app.globalData.CardList = list;
-
- that.closeTagShow();
- }
- },
- onGotoList: function () {
- var that = this;
- if (isFirstAdd == true || !that.data.Field) {
- wx.showModal({
- title: '提醒',
- content: '无法复查,因为没有上一张。从连续新建第二张题卡起可一键查看上一张题卡。',
- confirmText: '知道了',
- showCancel: false,
- });
- }
- else if (that.data.Field[1].length > 0 || that.data.Field[2].length > 0 || that.data.Field[2].length > 0) {
- wx.showModal({
- title: '提醒',
- content: '将离开编辑状态,请先保存题卡。',
- confirmText: '不保存',
- success(res) {
- if (res.confirm) {
- goto();
- setTimeout(function () {
- wx.removeStorageSync("TempCardNoSaved");
- }, 1000);
- }
- }
- });
- }
- else {
- goto();
- }
- function goto() {
- wx.showLoading({
- title: '请稍候',
- });
- setTimeout(function () {
- wx.hideLoading();
- }, 5000);
- var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
- main.getData(url, function (data) {
- wx.hideLoading();
- if (data) {
- app.globalData.CardList = data.List;
- that.setData({
- UpdateType: "add",
- });
- wx.navigateTo({
- url: './searchCardList?type=3&Count=' + data.Count,
- })
- }
- });
- }
- },
- //段落编辑**************************
- //字段输入
- bindinputField: function (e) {
- //console.log("bindinputField:" + e.detail.value + " isEdit:" + isEdit);
- var that = this;
- if (app.globalData.IsAndroid && !isEdit) {
- return;
- }
- this.setData({
- FieldContent: e.detail.value,
- });
- },
- //加符号
- 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: "[线]",
- });
- } else if (btnName == "[光]") {
- this.setData({
- HighlighterSign: "[/光]",
- });
- } else if (btnName == "[/光]") {
- this.setData({
- HighlighterSign: "[光]",
- });
- }
- if (btnName == "( )")
- btnName = "( )";
- else if (btnName == "_")
- btnName = "_____";
- //console.log("addSymbol_btnName:" + btnName);
- if (!this.data.Focus) {
- var obj = { detail: { cursor: tempCursor } };
- this.onBindblur(obj);
- }
- //console.log("addSymbol:" + this.data.FieldContent);
- setTimeout(function () {
- that.setData({
- Focus: true,
- });
- }, 300);
- },
- //焦点聚焦
- onBindFocus: function () {
- //console.log("onBindFocus");
- btnName = "";
- this.setData({
- Focus: true,
- });
- },
- //失焦
- onBindblur: function (e) {
- var that = this;
- //console.log("onBindblur:" + isEdit + " Filed:" + this.data.FieldContent);
- if (app.globalData.IsAndroid && !isEdit) {
- setTimeout(function () {
- isEdit = true;
- //console.log("onBindblur2:" + isEdit);
- }, 500);
- return;
- }
- isEdit = false;
- if (app.globalData.IsAndroid && !isEdit) {
- setTimeout(function () {
- isEdit = true;
- //console.log("onBindblur2:" + isEdit);
- }, 500);
- }
- //console.log("onBindblur:"+isEdit);
- this.updateField();
- tempCursor = e.detail.cursor;
- //console.log("tempCursor:" + tempCursor);
- if (tempCursor == undefined)
- tempCursor = this.data["FieldContent"].length;
- var str1 = "",
- str2 = "";
- if (this.data.FieldContent.length > 0) {
- str1 = this.data.FieldContent.substr(0, tempCursor);
- str2 = this.data.FieldContent.substring(tempCursor, this.data.FieldContent.length);
- }
- //console.log("str1:" + str1);
- //console.log("btnName:" + btnName);
- //console.log("str2:" + str2);
- var cur = 0;
- if (btnName) {
- cur = 1;
- if (btnName == "[读]" || btnName == "[线]" || btnName == "[光]") {
- cur = 3;
- } else if (btnName == "[/读]" || btnName == "[/线]" || btnName == "[/光]") {
- cur = 4;
- } else if (btnName === "( )") {
- cur = 7;
- } else if (btnName === "_____") {
- cur = 5;
- }
- }
- this.data.FieldContent = str1 + btnName + str2;
- this.setData({
- FieldContent: this.data.FieldContent,
- Focus: false,
- Cursor: tempCursor + cur,
- });
- btnName = "";
- },
- bindscrollHandler: function () {
- //console.log("bindscrollHandler");
- btnName = "";
- },
- onSearchField: function (e) {
- app.globalData.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({
- FieldContent: "",
- Focus: true,
- Cursor: 0,
- });
- btnName = "";
- isEdit = false;
- this.updateField();
- },
- closeAddItem: function (e) {
- var that = this;
- var isSave = e.currentTarget.dataset.idsave;
- if (isSave == "true") {
- isUnload = false;
- if (that.data.FieldContent) {
- var content = that.data.FieldContent;
- main.postData("MsgSecCheck2",
- { Content: content, },
- function (data) {
- if (data && data.errcode == 0) {
- next(that);
- } else {
- if (data.errmsg) {
- wx.showToast({
- title: data.errmsg,
- duration: 2000,
- image: "../images/universalpic_wrong_white_120x120.png",
- });
- isViolate = true;
- }
- }
- });
- } else {
- next(that);
- }
- } else if (isSave == "false") {
- var content = wx.getStorageSync("TempCardInfoAddItem");
- this.setData({
- FieldContent: content,
- });
- next(that);
- }
- function next(obj) {
- isViolate = false;
- obj.updateField();
- obj.setData({
- HiddenFieldEdit: true,
- });
- var title = "编辑题卡";
- if (obj.data.UpdateType == "add2") {
- title = "新建题卡";
- }
- that.setData({
- PageTitle: title,
- });
- }
- },
- updateField: function () {
- var str = this.data.FieldContent;
- var list = app.globalData.CardList;
- var card = {};
- for (var i = 0; i < list.length; i++) {
- if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- list[i].Content[this.data.FieldNumber].Content = str;
- card = main.changeStringToView(list[i].Content);
- break;
- }
- }
- app.globalData.CardList = list;
- this.setData({
- Field: card.Field,
- Tags: card.Tags,
- });
- },
- //选择图片上传
- uploadImageField: function () {
- //console.log("uploadImageStart");
- var that = this;
- //若是安卓机
- if (app.globalData.IsAndroid) {
- selectImage(that);
- } else {
- wx.showActionSheet({
- itemList: ['拍照', '从手机相册选择'],
- success(res) {
- if (res.tapIndex == 0) {
- wx.chooseImage({
- count: 1,
- sizeType: ['compressed'],
- sourceType: ['camera'],
- success(res2) {
- wx.showLoading({
- title: '请稍候',
- mask: true,
- });
- setTimeout(function () {
- wx.hideLoading();
- selectImage(that);
- }, 2000);
- },
- });
- } else if (res.tapIndex == 1) {
- selectImage(that);
- }
- },
- fail(res) {
- console.log(res.errMsg)
- }
- });
- }
- function selectImage(that) {
- var sizeType = ['album'];
- //若是安卓机
- if (app.globalData.IsAndroid)
- sizeType = ['album', 'camera'];
- wx.chooseImage({
- count: 1,
- sizeType: ['compressed'],
- sourceType: sizeType,
- success(res) {
- // tempFilePath可以作为img标签的src属性显示图片
- const tempFilePaths = res.tempFilePaths;
- //console.log(tempFilePaths[0]);
- //that.data.FieldContent = that.data.FieldContent + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
- wx.getImageInfo({
- src: res.tempFilePaths[0],
- success(res) {
- //console.log(res.width)
- //console.log(res.height)
- if (tempCursor == undefined)
- tempCursor = that.data.FieldContent.length;
- var str1 = "",
- str2 = "";
- if (that.data.FieldContent.length > 0) {
- str1 = that.data.FieldContent.substr(0, tempCursor);
- str2 = that.data.FieldContent.substring(tempCursor, that.data.FieldContent.length);
- }
- var width = res.width;
- if (isNaN(width))
- width = 650;
- var height = res.height;
- if (isNaN(height))
- height = 650;
- var str0 = "[图 w='" + width + "' h='" + height + "']" + tempFilePaths[0] + "[/图]";
- that.data.FieldContent = str1 + str0 + str2;
- tempCursor = that.data.FieldContent.length;
- //console.log("uploadImageEnd:" + that.data.FieldContent);
- that.setData({
- FieldContent: that.data.FieldContent,
- Focus: false,
- });
- that.updateField();
- if (!wx.getStorageSync("NoRemindImage")) {
- wx.showModal({
- title: '提醒',
- showCancel: true,
- content: "“图片记号”以符号[图]开始…以符号[/图]结尾。如要剪切请确保完整性。",
- confirmText: "好的",
- cancelText: "不再提醒",
- success(res) {
- if (res.confirm) { } else {
- wx.setStorageSync("NoRemindImage", true);
- }
- },
- });
- }
- }
- });
- },
- fail: function () {
- }
- });
- }
- },
- showPracticeTime: function () {
- if (this.data.MiaoguoCardID){
- wx.navigateTo({
- url: './previewMenu?IsSave=0&ID='+this.data.MiaoguoCardID+'&CardType='+this.data.CardType+"&LimitTime="+this.data.LimitTime,
- });
- }
- else{
- var limitTime=common.formatTime(new Date(),"-",true);
- if (this.data.LimitTime)
- limitTime=this.data.LimitTime;
- var cardType=0;
- if (this.data.CardType)
- cardType=this.data.CardType;
- wx.navigateTo({
- url: './previewMenu?IsSave=0&ID=0&CardType='+cardType+'&LimitTime='+limitTime,
- });
- }
- },
- //录音授权
- recorderAccredit: function () {
- var that = this;
- if (app.globalData.IsRecorderAccredit == 1)
- that.showRecorder();
- else if (app.globalData.IsRecorderAccredit == 0) {
- recorderManager.stop();
- app.globalData.IsRecorderAccredit = 1;
- that.showRecorder();
- } else if (app.globalData.IsRecorderAccredit == -1) {
- wx.getSetting({
- success(res) {
- if (res.authSetting['scope.record'] === true) {
- app.globalData.IsRecorderAccredit = 1;
- that.showRecorder();
- } else if (res.authSetting['scope.record'] === false) {
- wx.navigateTo({
- url: '../index/openSetting',
- });
- }
- }
- });
- }
- },
- showRecorder: function () {
- var that = this;
- if (that.checkRecorderCount()) {
- that.recorderInit();
- tempRecorderFile = "";
- that.setData({
- PageTitle: '录音',
- });
- that.setData({
- IsRecorder: true,
- IsRecorderFinished: false,
- BtnRecorderName: "按住录音1分钟",
- RecorderTime: "00:00",
- RecorderTimeCss: "",
- RecorderPlayName: "播放",
- });
- innerAudioContext = wx.createInnerAudioContext();
- innerAudioContext.onPlay(() => {
- console.log('开始播放');
- that.setData({
- RecorderTimeCss: "RecorderPanel1121",
- RecorderTime: "00:00",
- RecorderPlayName: "停止",
- });
- });
- innerAudioContext.onEnded(() => {
- console.log('结束播放');
- clearInterval(intervalRecorder);
- that.setData({
- RecorderTime: "00:00",
- RecorderTimeCss: "",
- RecorderPlayName: "播放",
- });
- });
- }
- },
- closeRecorder: function () {
- var that = this;
- this.recorderInit();
- if (tempRecorderFile) {
- wx.showModal({
- title: '提醒',
- content: '录音文件还未上传,要放弃录音吗?',
- showCancel: true,
- confirmText: "取消",
- cancelText: "不上传",
- success(res) {
- if (res.cancel) {
- closeRecorder2();
- }
- },
- })
- } else {
- closeRecorder2();
- }
- function closeRecorder2() {
- that.setData({
- PageTitle: '编辑 段落' + that.data.FieldNumber,
- });
- that.setData({
- IsRecorder: false,
- IsRecorderFinished: false,
- });
- tempRecorderFile = "";
- }
- },
- //录音初始化
- recorderInit: function () {
- if (innerAudioContext)
- innerAudioContext.stop();
- if (recorderManager)
- recorderManager.stop();
- clearInterval(intervalRecorder);
- },
- checkRecorderCount: function (arr) {
- var that = this;
- var count = 0;
- if (that.data.FieldContent.indexOf("[音 url=") >= 0 ||
- that.data.FieldContent.indexOf("[/音]") >= 0) {
- count = 1;
- }
- if (count > 0) {
- wx.showToast({
- title: '仅能上传一段',
- });
- return false;
- } else
- return true;
- },
- btnRecorderStart: function () {
- var that = this;
- if (app.globalData.IsRecorderAccredit == 1) {
- that.setData({
- BtnRecorderName: "松手结束",
- RecorderTimeCss: "RecorderPanel1121",
- });
- that.showRecorderTime();
- recorderManager.start();
- }
- },
- btnRecorderEnd: function () {
- var that = this;
- if (app.globalData.IsRecorderAccredit == 1) {
- if (that.data.RecorderTime == "00:00") {
- //小于1秒处理
- wx.showToast({
- title: '时间过短',
- image: "../images/universalpic_warning_white_126x120.png",
- });
- that.showRecorder();
- } else {
- that.setData({
- IsRecorderFinished: true,
- RecorderTimeCss: "",
- });
- that.recorderInit();
- }
- } else {
- that.recorderAccredit();
- }
- },
- showRecorderTime: function () {
- var that = this;
- var second = 0;
- clearInterval(intervalRecorder);
- intervalRecorder = setInterval(function () {
- second++;
- var secondStr = second.toString();
- if (second < 10)
- secondStr = "0" + secondStr;
- that.setData({
- RecorderTime: "00:" + secondStr,
- });
- if (second >= 59) {
- that.setData({
- IsRecorderFinished: true,
- RecorderTimeCss: "",
- });
- that.recorderInit();
- if (that.data.RecorderPlayName == "播放") {
- wx.showToast({
- title: '录音超时',
- image: "../images/universalpic_warning_white_126x120.png",
- });
- }
- }
- }, 1000);
- },
- btnRecorderPlay: function () {
- var that = this;
- if (tempRecorderFile && this.data.RecorderPlayName == "播放") {
- innerAudioContext.src = tempRecorderFile;
- innerAudioContext.play();
- this.showRecorderTime();
- } else if (this.data.RecorderPlayName == "停止") {
- if (innerAudioContext)
- innerAudioContext.stop();
- clearInterval(intervalRecorder);
- that.setData({
- RecorderTime: "00:00",
- RecorderTimeCss: "",
- RecorderPlayName: "播放",
- });
- }
- },
- btnRecorderSave: function () {
- var that = this;
- this.recorderInit();
- wx.showLoading({
- title: '正在上传',
- });
- setTimeout(function () {
- wx.hideLoading();
- }, 60000);
- that.uploadFileToServer(tempRecorderFile, function (data) {
- if (data) {
- data = JSON.parse(data);
- //console.log(data);
- wx.hideLoading();
- var result = data.result;
- result.Target = app.globalData.uploadImageUrl + result.Target;
- that.data.FieldContent = that.data.FieldContent + "[音 url='" + result.Target + "'][/音]";
- that.data.FieldContent = main.encryptUrl(that.data.FieldContent);
- that.setData({
- FieldContent: that.data.FieldContent,
- });
- tempRecorderFile = "";
- that.closeRecorder();
- if (!wx.getStorageSync("NoRemindRecorder")) {
- wx.showModal({
- title: '提醒',
- showCancel: true,
- content: "“录音记号”以符号[录]开始…以符号[/录]结尾。如要剪切请确保完整性。",
- confirmText: "好的",
- cancelText: "不再提醒",
- success(res) {
- if (res.confirm) { } else {
- wx.setStorageSync("NoRemindRecorder", true);
- }
- },
- });
- }
- }
- });
- },
- gotoSymbol: function (e) {
- wx.navigateTo({
- url: '../main/symbolsetting',
- });
- },
- gotoTest: function () {
- var that=this;
- if (that.data.Field[1].length > 0 || that.data.Field[2].length > 0 || that.data.Field[2].length > 0) {
- wx.showModal({
- title: '尚未保存',
- content: '即将打开“知识检验”功能,但当前题卡尚未保存,按继续将放弃保存。',
- confirmText: '继续',
- success(res) {
- if (res.confirm) {
-
- wx.redirectTo({
- url: '../test/index',
- });
- setTimeout(function(){
- wx.removeStorageSync("TempCardNoSaved");
- },1000);
- }
- }
- });
- }
- else {
- wx.redirectTo({
- url: '../test/index',
- });
- }
- },
- showTagShow:function(){
- var tagTemp=this.data.Tags.join(",");
- this.setData({
- IsTagShow:true,
- TagTemp:tagTemp.split(","),
- TagIndex:-1,
- });
- this.setData({
- PageTitle: '自动记号',
- });
- },
- closeTagShow:function(){
- this.setData({
- IsTagShow:false,
- });
- this.setData({
- PageTitle: '编辑题卡',
- });
- },
- setCardTypeInit:function(){
- this.setData({
- CardType:0,
- PracticeCardType:"日常",
- PracticeTimeStr:"",
- LimitTime:common.formatTime(new Date(),"-",true),
- IsEditCardType:"",
- });
- wx.showToast({
- title: '已恢复默认',
- image: "../images/universalpic_restore_white_120x120.png",
- });
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|