- 开放标签在微信页面中部显示,不报错是为什么?
使用H5页面跳转小程序,使用的是官方示例,用手机微信扫码能打开示例小程序,把页面传到静态网站上,在手机微信里面打开页面链接,“打开小程序”的按钮就不显示,在手机浏览器中打开,可以正常打开小程序链接,后台也没有报错,不知道错误出在哪里。 页面代码如下: <html> <head> <title>打开小程序</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1"> <script> window.onerror = e => { console.error(e) alert('发生错误' + e) } </script> <!-- weui 样式 --> <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.1/weui.min.css"></link> <!-- 调试用的移动端 console --> <script src="https://cdn.jsdelivr.net/npm/eruda"></script> <script>eruda.init();</script> <!-- 公众号 JSSDK --> <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> <!-- 云开发 Web SDK --> <script src="https://res.wx.qq.com/open/js/cloudbase/1.1.0/cloud.js"></script> <script> function docReady(fn) { if (document.readyState === 'complete' || document.readyState === 'interactive') { fn() } else { document.addEventListener('DOMContentLoaded', fn); } } docReady(async function() { var ua = navigator.userAgent.toLowerCase() var isWXWork = ua.match(/wxwork/i) == 'wxwork' var isWeixin = !isWXWork && ua.match(/MicroMessenger/i) == 'micromessenger' var isMobile = false var isDesktop = false if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) { isMobile = true } else { isDesktop = true } console.warn('ua', ua) console.warn(ua.match(/MicroMessenger/i) == 'micromessenger') var m = ua.match(/MicroMessenger/i) console.warn(m && m[0] === 'micromessenger') if (isWeixin) { console.log('微信中打开') var containerEl = document.getElementById('wechat-web-container') containerEl.classList.remove('hidden') containerEl.classList.add('full', 'wechat-web-container') var launchBtn = document.getElementById('launch-btn') launchBtn.addEventListener('ready', function (e) { console.log('开放标签 ready') }) launchBtn.addEventListener('launch', function (e) { console.log('开放标签 success') }) launchBtn.addEventListener('error', function (e) { console.log('出现错误') console.log('开放标签 fail', e.detail) }) wx.config({ // debug: true, // 调试时可开启 appId: 'wx69246cff66cad933', timestamp: 0, // 必填,填任意数字即可 nonceStr: 'nonceStr', // 必填,填任意非空字符串即可 signature: 'signature', // 必填,填任意非空字符串即可 jsApiList: ['chooseImage'], // 安卓上必填一个,随机即可 openTagList:['wx-open-launch-weapp'], // 填入打开小程序的开放标签名 }) } else if (isDesktop) { // 在 pc 上则给提示引导到手机端打开 var containerEl = document.getElementById('desktop-web-container') containerEl.classList.remove('hidden') containerEl.classList.add('full', 'desktop-web-container') } else { var containerEl = document.getElementById('public-web-container') containerEl.classList.remove('hidden') containerEl.classList.add('full', 'public-web-container') var c = new cloud.Cloud({ // 必填,表示是未登录模式 identityless: true, // 资源方 AppID resourceAppid: 'wx69246cff66cad933', // 资源方环境 ID resourceEnv: 'lgd001-lgd', }) await c.init() window.c = c var buttonEl = document.getElementById('public-web-jump-button') var buttonLoadingEl = document.getElementById('public-web-jump-button-loading') try { await openWeapp(() => { buttonEl.classList.remove('weui-btn_loading') buttonLoadingEl.classList.add('hidden') }) } catch (e) { buttonEl.classList.remove('weui-btn_loading') buttonLoadingEl.classList.add('hidden') throw e } } }) async function openWeapp(onBeforeJump) { var c = window.c const res = await c.callFunction({ name: 'public', data: { action: 'getUrlScheme', }, }) console.warn(res) if (onBeforeJump) { onBeforeJump() } location.href = res.result.openlink } </script> <style> .hidden { display: none; } .full { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .public-web-container { display: flex; flex-direction: column; align-items: center; } .public-web-container p { position: absolute; top: 40%; } .public-web-container a { position: absolute; bottom: 40%; } .wechat-web-container { display: flex; flex-direction: column; align-items: center; } .wechat-web-container p { position: absolute; top: 40%; } .wechat-web-container wx-open-launch-weapp { position: absolute; bottom: 40%; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; } .desktop-web-container { display: flex; flex-direction: column; align-items: center; } .desktop-web-container p { position: absolute; top: 40%; } </style> </head> <body> <div class="page full"> <div id="public-web-container" class="hidden"> <p class="">正在打开 “大理招商项目查询aa”...</p> <a id="public-web-jump-button" href="javascript:" class="weui-btn weui-btn_primary weui-btn_loading" onclick="openWeapp()"> <span id="public-web-jump-button-loading" class="weui-primary-loading weui-primary-loading_transparent"><i class="weui-primary-loading__dot"></i></span> 打开小程序 </a> </div> <div id="wechat-web-container" class="hidden"> <p class="">点击以下按钮打开 “大理招商项目查询bbb”</p> <!-- 跳转小程序的开放标签。文档 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html --> <wx-open-launch-weapp id="launch-btn" username="xxxxxxxxx" path="/pages/ppmindex/ppm"> <template> <button style="width: 200px; height: 45px; text-align: center; font-size: 17px; display: block; margin: 0 auto; padding: 8px 24px; border: none; border-radius: 4px; background-color: #07c160; color:#fff;">打开小程序</button> </template> </wx-open-launch-weapp> </div> <div id="desktop-web-container" class="hidden"> <p class="">请在手机打开网页链接</p> </div> </div> </body> </html>
2021-08-18 - nodejs图片上传如何取formData数据???
图片上传过程中需要在formData中添加其他数据,用于数据更新,代码如下 [代码]// 上传图片接口[代码][代码]doUpload: [代码][代码]function[代码] [代码](e) {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码] [代码][代码]// 选择图片[代码][代码] [代码][代码]console.log([代码][代码]'ID:'[代码][代码], e.target.id)[代码][代码] [代码][代码]wx.chooseImage({[代码][代码] [代码][代码]count: 1,[代码][代码] [代码][代码]sizeType: [[代码][代码]'compressed'[代码][代码]],[代码][代码] [代码][代码]sourceType: [[代码][代码]'album'[代码][代码], [代码][代码]'camera'[代码][代码]],[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]util.showBusy([代码][代码]'正在上传'[代码][代码])[代码][代码] [代码][代码]var[代码] [代码]filePath = res.tempFilePaths[0][代码][代码] [代码][代码]// 上传图片[代码][代码] [代码][代码]wx.uploadFile({[代码][代码] [代码][代码]url: config.service.uploadUrl,[代码][代码] [代码][代码]filePath: filePath,[代码][代码] [代码][代码]name: [代码][代码]'file'[代码][代码],[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]ID: e.target.id,[代码][代码] [代码][代码]name:[代码][代码]'aaaaaaaaa'[代码][代码] [代码][代码]},[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]util.showSuccess([代码][代码]'上传图片成功'[代码][代码])[代码][代码] [代码][代码]console.log([代码][代码]'返回值:'[代码][代码], res)[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]List: res.data.data[0][代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](e) {[代码][代码] [代码][代码]util.showModel([代码][代码]'上传图片失败'[代码][代码])[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](e) {[代码][代码] [代码][代码]console.error(e)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码]},[代码]server 端代码如下 [代码]const { uploader } = require([代码][代码]'../qcloud'[代码][代码])[代码][代码]const { mysql } = require([代码][代码]'../qcloud'[代码][代码])[代码][代码]module.exports = async ctx => {[代码][代码] [代码][代码]// 获取上传之后的结果[代码][代码] [代码][代码]// 具体可以查看:[代码][代码] [代码][代码]console.log([代码][代码]'##############################'[代码][代码]);[代码][代码] [代码][代码]console.log(ctx.request.body);[代码][代码] [代码][代码]console.log([代码][代码]'#############################'[代码][代码]);[代码][代码] [代码][代码]const data = await uploader(ctx.req)[代码][代码] [代码][代码]//console.log(data);[代码][代码] [代码][代码]var[代码] [代码]imgUrl = data.imgUrl;[代码][代码] [代码][代码]//console.log(data.imgUrl);[代码][代码] [代码][代码]var[代码] [代码]ID = ctx.request.body.ID[代码][代码];[代码][代码] [代码][代码]//console.log(ID);[代码][代码] [代码][代码]var[代码] [代码]res = [代码][代码]null[代码][代码];[代码][代码] [代码][代码]var[代码] [代码]sql = [代码][代码]"update t_zone set f_img='"[代码] [代码]+ imgUrl + [代码][代码]"' where f_id="[代码] [代码]+ ID;[代码][代码] [代码][代码]await mysql.schema.raw(sql)[代码][代码] [代码][代码]res = await mysql.schema.raw([代码][代码]"select * from t_zone where 1=1 "[代码][代码])[代码][代码] [代码][代码]ctx.state.data = res;[代码][代码] [代码][代码]//ctx.state.data = data[代码][代码]}[代码]不知道怎么把ID和name值取出,请大家帮我看看。
2018-05-14