123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- // pages/checkTitle/checkTitle.js
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- myWordList: [],
- wordList: [],
- keyword: '',
- word: '',
- type: 0,
- author: '',
- from: '',//当上级页面时二维码是有值
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- type: options.type,
- author: options.author,
- word: options.word,
- openId: wx.getStorageSync('userInfo').openId,
- from: options.from //来源 2是二维码转换 1是作者名字 0是引导词
- })
- var params = options.from==0?'word':'author'
- this.setData({
- keyword: wx.getStorageSync(params)
- })
- this.data.from=='qrcode'&&this.setData({
- type: 2
- })
-
- // type:0 引导词 1:作者名字
- this.getword();
- this.getMyWord();
- },
- getMyWord() {
- wx.showLoading({
- title: '加载中',
- })
- app.func.req('/api/article/getMyWords', 'get', {
- 'openid': this.data.openId
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- //成功
- this.setData({
- myWordList: res.rst.data
- })
- }else {
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- getword() {
- app.func.req('/api/article/getGuideWords', 'get', {
- 'type': this.data.from
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- //成功
- this.setData({
- wordList: res.rst.data
- })
- }else {
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- getKeyword(e) {
- this.setData({
- keyword: e.detail.value
- })
- },
- saveWord() {
- app.func.req('/api/article/addWord', 'post', {
- 'keyword': this.data.keyword
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- //成功
- wx.showToast({
- title: '引导词保存成功',
- })
- this.getMyWord();
- }else {
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- // 选择内容
- checkWord(e) {
- wx.pageScrollTo({
- scrollTop: 0,
- duration: 300
- })
- this.setData({
- keyword: e.currentTarget.dataset.word
- })
- },
- toLink(e) {
- var word = e.currentTarget.dataset.word?e.currentTarget.dataset.word:this.data.keyword
- switch (this.data.from) {
- case '0':
- wx.setStorageSync('word',word)
- wx.redirectTo({
- url: this.data.type=='program'?'/pages/appletEdit/appletEdit?from=word':'/pages/link/index?from=word'
- })
- break;
- case '1':
- wx.setStorageSync('author',word)
- wx.redirectTo({
- url: this.data.type=='program'?'/pages/appletEdit/appletEdit?from=word':'/pages/link/index?from=word'
- })
- break;
- case '2':
- wx.setStorageSync('introduce',word)
- wx.redirectTo({
- url: '/pages/qrcode/qrcode?from=word'
- })
- break;
- default:
- break;
- }
- },
- delWord(e) {
- app.func.req('/api/article/delWord', 'post', {
- 'keyword': e.currentTarget.dataset.word
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- //成功
- wx.showToast({
- title: '删除词库成功',
- })
- this.getMyWord();
- }else {
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- onShareAppMessage() {
-
- }
- })
|