123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- // pages/link/index.js
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- keyword: '',
- searchKeyword: '',
- openId: '',
- word: '',
- author: '',
- text: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- keyword: this.options.word,
- openId: wx.getStorageSync('userInfo').openId,
- word: wx.getStorageSync('word'),
- author: wx.getStorageSync('author')
- })
- this.getText();
- // 上级目录是word时,使用保存的word
- if(options.from) {
- this.setData({
- keyword: wx.getStorageSync('keyword')
- })
- }
- !this.data.word&&this.getword(0);
- !this.data.author&&this.getword(1);
- },
- getText() {
- wx.showLoading({
- title: '加载中',
- })
- app.func.req('/api/app/config', 'get', {
- 'version': '1.0.1'
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- this.setData({
- text: res.rst.platform
- })
- }else {
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- getCopy() {
- var that = this;
- wx.getClipboardData({
- success (res){
- that.setData({
- keyword: res.data
- })
- }
- })
- },
- getKeyword(e) {
- this.setData({
- searchKeyword: e.detail.value,
- keyword: e.detail.value
- })
- },
- clearAll() {
- this.setData({
- keyword: ''
- })
- },
- toWord(e) {
- // 保存关键词
- wx.setStorageSync('keyword',this.data.keyword)
- wx.redirectTo({
- url: '/pages/word/word?from='+e.currentTarget.dataset.type+'&word='+this.data.word+'&author='+this.data.author
- })
- },
- // 获取链接
- getUrl(content) {
- var content = this.data.keyword;
- if(!content) {
- wx.showToast({
- title: '内容不能为空',
- icon: 'none'
- })
- return;
- }
- wx.showLoading({
- title: '加载中',
- })
- app.func.req('/api/goods/goods_info', 'post', {
- 'url': content
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- //成功
- wx.setStorageSync('shopInfo',res.rst)
- setTimeout(() => {
- wx.redirectTo({
- url: '/pages/status/status'
- })
- },400)
- }else {
- wx.showToast({
- title: res.err?res.err:'服务器错误',
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.showToast({
- title: '链接转换失败',
- icon: 'none',
- duration: 2000
- })
- wx.hideLoading()
- })
- },
- // 没有本地词,从列表中获取----默认引导词
- getword(type) {
- app.func.req('/api/article/getGuideWords', 'get', {
- 'type': type
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- if(type==0) {
- this.setData({
- word: res.rst.data[0].keyword
- })
- wx.setStorageSync('word',res.rst.data[0].keyword)
- }else {
- //成功
- this.setData({
- author: res.rst.data[0].keyword
- })
- wx.setStorageSync('author',res.rst.data[0].keyword)
- }
- }else {
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- onShareAppMessage() {
-
- }
- })
|