| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- const PracticeTimeArr = [{
- Name: "还原",
- CSS: "numberContainerFooter1121Select"
- },
- {
- Name: "今天必练",
- },
- {
- Name: "推迟一周",
- },
- {
- Name: "推迟一个月",
- },
- {
- Name: "推迟三个月",
- }
- ];
- 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,
- PracticeTimeArr: PracticeTimeArr,
- IsIPhoneX: app.globalData.IsIPhoneX,
- },
- 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) => {
- // console.log('err', err);
- // if (err.errMsg =="operateRecorder:fail auth deny"){
- // wx.navigateTo({
- // url: '../index/openSetting',
- // })
- // }
- });
- },
- 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,
- PracticeTimeStr: PracticeTimeArr[0].Name,
- IsShow: app.globalData.userInfo.IsShow,
- IsShowPracticeTimeStart: true,
- });
- 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;
- },
- onShow: function () {
- var that = this;
- if (that.data.UpdateType == "add") {
- that.initAddCard();
- that.setData({
- PracticeTimeStr2: "智能安排",
- });
- } 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;
- card.LimitTime = list[i].LimitTime;
- if (that.data.FieldNumber && that.data.FieldNumber > 0)
- content = main.encryptUrl(list[i].Content[that.data.FieldNumber].Content);
- break;
- }
- }
- that.setData({
- MiaoguoCardID: card.MiaoguoCardID,
- LimitTime: common.formatTime(card.LimitTime),
- PracticeTimeStr2: common.formatDateCHS(common.formatTime(card.LimitTime)),
- Field: card.Field,
- Tags: card.Tags,
- FieldContent: content,
- });
- if (that.data.UpdateType != "add2") {
- wx.setNavigationBarTitle({
- title: '编辑题卡'
- });
- }
- 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();
- },
- 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,
- });
- wx.setNavigationBarTitle({
- title: '编辑 段落' + 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: '第一段必填',
- image: "../images/universalpic_wrong_white_120x120.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: '第一段必填',
- image: "../images/universalpic_wrong_white_120x120.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.IsTodayStudy = 0;
- if (that.data.PracticeTimeStr == PracticeTimeArr[1].Name)
- param1.IsTodayStudy = 1;
- param1.LimitTime = that.getLimitTimeStr();
- 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();
- wx.showToast({
- title: '已保存!',
- image: "../images/universalpic_saved_white_120x120.png",
- });
- if (that.data.UpdateType == "add2") {
- isFirstAdd = false;
- that.initAddCard();
- }
- }
- wx.removeStorageSync("TempCardInfo");
- });
- } 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[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;
- wx.showModal({
- title: '提醒',
- content: '记号“' + that.data.Tags[index] + '”要删除吗?',
- success(res) {
- if (res.confirm) {
- that.data.Tags.splice(index, 1);
- that.setData({
- Tags: that.data.Tags,
- });
- 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;
- }
- }
- });
- },
- 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 = 'GetMiaoguoCardList?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=2&Count=' + data.Count,
- })
- }
- });
- }
- },
- getLimitTimeStr: function () {
- var that = this;
- if (!that.data.LimitTime)
- that.data.LimitTime = common.formatTime(new Date());
- var LimitTime = common.formatTime(new Date(that.data.LimitTime));
- if (that.data.PracticeTimeStr == PracticeTimeArr[1].Name)
- LimitTime = common.formatTime(new Date());
- else if (that.data.PracticeTimeStr == PracticeTimeArr[2].Name)
- LimitTime = common.formatTime(common.addDate("w", 1, new Date(that.data.LimitTime)));
- else if (that.data.PracticeTimeStr == PracticeTimeArr[3].Name)
- LimitTime = common.formatTime(common.addDate("m", 1, new Date(that.data.LimitTime)));
- else if (that.data.PracticeTimeStr == PracticeTimeArr[4].Name)
- LimitTime = common.formatTime(common.addDate("m", 3, new Date(that.data.LimitTime)));
- //console.log(that.data.LimitTime);
- //console.log(new Date(that.data.LimitTime));
- //console.log(common.addDate("w", 1, new Date(that.data.LimitTime)));
- //console.log(LimitTime);
- return LimitTime
- },
- //段落编辑**************************
- //字段输入
- 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 = "添加题卡";
- }
- wx.setNavigationBarTitle({
- title: 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: "不再提示",
- confirmColor: "#0071EF",
- success(res) {
- if (res.confirm) { } else {
- wx.setStorageSync("NoRemindImage", true);
- }
- },
- });
- }
- }
- });
- },
- fail: function () {
- }
- });
- }
- },
- onPracticeTime: function (e) {
- var that = this;
- var value = e.currentTarget.dataset.value;
- that.data.IsShowPracticeTimeStart = true;
- if (that.data.IsShowPracticeTimeStart && value != "还原") {
- that.data.IsShowPracticeTimeStart = false;
- }
- that.setData({
- IsPracticeTime: false,
- PracticeTimeStr: value,
- IsShowPracticeTimeStart: that.data.IsShowPracticeTimeStart,
- });
- var PracticeTimeStr2 = common.formatDateCHS(common.formatTime(that.data.LimitTime));
- if (value != "还原")
- PracticeTimeStr2 = common.formatDateCHS(common.formatTime(that.getLimitTimeStr(value)));
- else
- if (that.data.UpdateType === "add" || that.data.UpdateType === "add2")
- PracticeTimeStr2 = "智能安排";
- that.setData({
- PracticeTimeStr2: PracticeTimeStr2,
- });
- },
- showPracticeTime: function () {
- this.setData({
- IsPracticeTime: true,
- });
- },
- closePracticeTime: function () {
- this.setData({
- IsPracticeTime: false,
- });
- },
- //录音授权
- 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 = "";
- wx.setNavigationBarTitle({
- title: '录音',
- });
- that.setData({
- IsRecorder: true,
- IsRecorderFinished: false,
- BtnRecorderName: "按住录音",
- 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: "取消",
- cancelColor: "#000000",
- cancelText: "继续",
- confirmColor: "#000000",
- success(res) {
- if (res.cancel) {
- closeRecorder2();
- }
- },
- })
- } else {
- closeRecorder2();
- }
- function closeRecorder2() {
- wx.setNavigationBarTitle({
- title: '编辑 段落' + 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_wrong_white_120x120.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_wrong_white_120x120.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: "不再提示",
- confirmColor: "#0071EF",
- 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',
- });
- }
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|