浙政钉小程序总结

本文介绍了浙政钉小程序的参数获取方式、下拉刷新机制、生命周期管理、授权码获取及WebSocket通信等关键技术要点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

浙政钉小程序总结

  1. 扫码进入浙政钉小程序指定页面后 前端怎么获取到里面的参数
    首先生成二维码的链接:taurus://taurusclient/action/open_app?appId=0201027143446479&type=2&page=pages%2Findex%2Findex%3FqrCodeId%3D168%26appId%3D1%26appName%3D%E6%B5%8B%E8%AF%95;appId:指的是创建的小程序appId,type:2 表示小程序,page=“”指定进入的页面以及参数传递。page= 后面的字符串需要进行UrIEncode编码,例如:pages/index/index?qrCodeId=168&appId=1&appName=测试编码后为~~pages%2findex%2findex%3fqrCodeId%3d168%26appId%3d1%26appName%3d%e6%b5%8b%e8%af%95~~ 将下划线即编码后的字符串赋值给page。此时在指定页面中可以直接在onLoad的函数中通过options.appId等获取参数值。
  2. 下拉刷新的事件不会触发
    首先看下当前页面的.json文件中是否配置了"pullRefresh": true ,同时app.json中的window对象中也需要配置"allowsBounceVertical": "YES"。如果两个值都配置了还是不可以进行下拉刷新或上拉加载那就是css样式问题导致了,当页面内容不满时不会触发上拉加载。
  3. 生命周期中的onLaunch和page.onLoad
    正常情况下,打印日志或一些静态方法等可以看到是先打印app.js中onLaunch然后再试onLoad函数,但是如果是异步操作,比如你在小程序运行时onLaunch中刷新下Token,然后在首页的onLoad 函数中用这个刷新的token是不存在的,事实上会先执行page.onLoad函数中的异步请求,再执行onLaunch中的异步请求。和vue中created函数和mounted函数是完全不一样,这种情况下可以在首页去做onLaunch中的异步操作。
  4. 获取授权码
    在编辑器中调用方法my.getAuthCode().then((res)=>{ console.log(res) this.setData({ rescode:res.result.code }) }) 会报错,此时不要慌,因为获取这个授权码需要在真机调试中才可以获取到。同时如果用my.去获取取值时为res.result.code,用dd.getAuthCode({}).then((res) => { resolve(res) }) 取值为res.code;
  5. websocket
    浙政钉小程序中每次建立websocket链接都需要重新监听其相关事件,如接受消息的onSocketMessage,以及监听链接成功的onSocketOpen等等。
  6. 自己封装的util.js分享下

状态码判断这块符合restful风格接口
在这里插入图片描述

import dd from 'gdt-jsapi';;

const ip = "192.168.0.167:8080";//龙
// const ip = "192.168.0.238:8080";//熊
// const ip = "192.168.0.37:8080";//王者
// const ip = "192.168.0.136:8080";//超
// const ip = "192.168.0.223:8080";//伟
// const ip = "192.168.0.46";//斌
const baseUrl = "http://"+ip; 
const wsbaseUrl = "ws://"+ip+"/websocket";


/**
 * 
 * @param {*} callback  获取免登授权码成功回调
 * 
 */
const getAuthCode = function () {
	return new Promise((resolve, reject) => {
		dd.getAuthCode({}).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
/**
 * 
 * @param {*} content  弱提示内容
 */
const toast = function (content) {
	dd.showToast({
		content: content,
	})
}




// 接口未调通错误处理
const errMsg = function (err) {
	if (err.error == 19) {
		// toast('异常http状态码错误' + err.status)
		// toast(err.data.message || err.errorMessage)
		// 处理下token失效等问题
		exceptionMsg(err.data.code, err);
	} else if (err.error == 11) {
		toast('无权跨域')
	} else if (err.error == 12) {
		toast('网络出错如网络不通等')
	} else if (err.error == 13) {
		toast('请求超时')
	} else if (err.error == 14) {
		toast('解码失败,http请求返回的内容格式是与dataType设置的类型不一致')
	} else {
		toast(err.errorMessage)
	}
};

// 针对于code码处理 
const exceptionMsg = function (code, res,options) {
	switch (parseInt(code)) {
		case 2001:
			clearStorage();
			if(options){
				console.log(options)
			}
			redirectTo('/pages/index/index')
			break;
		default:
			toast(res.data.message || res.errorMessage);
			return false;
	}
}

const  existsToken = function(url){
	if(!getStorage('token
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值