123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- // pages/appletEdit/appletEdit.js
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- itemObj: {},
- imgUrl: '',
- word: '',
- author: '',
- path: 'pages/index/index',
- b64: '',
- canvasWidth: '',
- canvasHeight: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if(options.from) {
- this.setData({
- word: wx.getStorageSync('word'),
- author: wx.getStorageSync('author'),
- itemObj: wx.getStorageSync('programObj'),
- b64: wx.getStorageSync('proImg'),
- path: wx.getStorageSync('path'),
- })
- }else {
- !this.data.word&&this.getword(0);
- !this.data.author&&this.getword(1);
- }
- this.setData({
- itemObj: wx.getStorageSync('itemObj'),
- word: wx.getStorageSync('word'),
- author: wx.getStorageSync('author'),
- })
- wx.setNavigationBarTitle({
- title: this.data.itemObj.app_name
- })
- this.getSetting()
- },
-
- toStatus() {
- if(!this.data.path) {
- wx.showToast({
- icon: 'none',
- title: '小程序路径不能为空',
- })
- return;
- }
- wx.setStorageSync('word',this.data.word)
- wx.setStorageSync('author',this.data.author)
- wx.setStorageSync('programObj',this.data.itemObj)
- wx.redirectTo({
- url: '/pages/status/status?post='+(this.data.b64?this.data.b64:this.data.imgUrl)+'&app_id='+this.data.itemObj.app_id+'&path='+this.data.path
- })
- },
- // 上传
- fetch() {
- wx.chooseImage({
- success: res => {
- wx.showLoading({
- title: '上传中',
- icon: 'none'
- })
- wx.getFileSystemManager().readFile({
- filePath: res.tempFilePaths[0], //选择图片返回的相对路径
- encoding: 'base64', //编码格式
- success: res => { //成功的回调
- this.getUrl('data:image/png;base64,' + res.data)
- },
- fail(error) {
- console.log(error)
- }
- })
- }
- })
- },
- getUrl(url) {
- app.func.req('/api/upload/img', 'post', {
- 'img': url
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- if(!res.rst.file_path) {
- wx.showToast({
- title: '图片上传失败',
- icon: 'none'
- })
- return;
- }
- //成功
- this.setData({
- b64: res.rst.file_path
- })
- }else {
- wx.showToast({
- title: res.err,
- 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()
- })
- },
- toWord(e) {
- // 保存关键词
- wx.setStorageSync('proImg',this.data.b64)
- wx.setStorageSync('keyword',this.data.keyword)
- wx.setStorageSync('path',this.data.path)
- wx.setStorageSync('programObj',this.data.itemObj)
- wx.redirectTo({
- url: '/pages/word/word?from='+e.currentTarget.dataset.type+'&word='+this.data.word+'&author='+this.data.author+'&type=program'
- })
- },
- getKeyword(e) {
- this.setData({
- path: e.detail.value
- })
- },
- getSetting(e) {
- wx.showLoading({
- title: '加载中',
- })
- app.func.req('/api/weapp/config', 'get',{
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- //成功
- this.setData({
- imgUrl: res.rst.def_main_img
- })
- }else {
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- onShareAppMessage() {
-
- }
- })
|