提交 587406a3 authored 作者: 黄旭新's avatar 黄旭新

引入微信SDK

上级 d92c6725
<script> <script>
import api from '@/static/util/api.js'
import {post,get} from '@/static/util/fun.js'
import jweixin from 'jweixin-module'
export default { export default {
onLaunch: function() { onLaunch: function() {
console.log('App Launch') console.log('App Launch')
}, },
created() {
let that=this
//请求接口获取签名时间戳
post(api.sign).then(res=>{
if(res.code==200){
that.timestamp=res.data.timestamp
that.nonceStr=res.data.nonceStr
that.signature=res.data.signature
jweixin.config({
debug: false,
appId: 'wx85eaf2734af145bd',
timestamp: that.timestamp,
nonceStr: that.nonceStr,
signature:that.signature,
jsApiList: ['updateTimelineShareData','updateAppMessageShareData','scanQRCode']
});
jweixin.ready(function() {
if(that.ispause){
innerAudioContext.pause();
}else{
innerAudioContext.play();
}
//分享给朋友接口
jweixin.updateAppMessageShareData({
title: '敏捷集团党史知识竞赛', // 分享标题
desc: '我在参加敏捷集团党史知识竞赛,一起来战吧!', // 分享描述
link: 'https://faces.diaosaas.com/party-history-h5/', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: 'https://faces.diaosaas.com/party-history-h5/mp3/wxshare.png', // 分享图标
success: function () {
console.log('分享成功!')
}
})
//分享到朋友圈接口
jweixin.updateTimelineShareData({
title: '敏捷集团党史知识竞赛', // 分享标题
link: 'https://faces.diaosaas.com/party-history-h5/', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: 'https://faces.diaosaas.com/party-history-h5/mp3/wxshare.png', // 分享图标
success: function () {
// 设置成功
console.log('分享成功!')
}
})
});
}
})
},
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')
}, },
onHide: function() { onHide: function() {
console.log('App Hide') console.log('App Hide')
},
methods:{
jssdk(){
}
} }
} }
</script> </script>
<style> <style lang="scss">
@import 'uview-ui/index.scss';
/*每个页面公共css */ /*每个页面公共css */
view {
box-sizing: border-box;
}
image {
width: 100%;
height: 100%;
}
</style> </style>
# jweixin-module
微信JS-SDK
## 安装
### NPM
```shell
npm install jweixin-module --save
```
### UMD
```http
https://unpkg.com/jweixin-module/out/index.js
```
## 使用
```js
var jweixin = require('jweixin-module')
jweixin.ready(function(){
// TODO
});
```
## 完整API
>[微信JS-SDK说明文档](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115)
差异被折叠。
{
"_from": "jweixin-module",
"_id": "jweixin-module@1.6.0",
"_inBundle": false,
"_integrity": "sha512-dGk9cf+ipipHmtzYmKZs5B2toX+p4hLyllGLF6xuC8t+B05oYxd8fYoaRz0T30U2n3RUv8a4iwvjhA+OcYz52w==",
"_location": "/jweixin-module",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "jweixin-module",
"name": "jweixin-module",
"escapedName": "jweixin-module",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/jweixin-module/-/jweixin-module-1.6.0.tgz",
"_shasum": "4a7ea614083e3c9c3f49e2fdc2bb882cfa58dfcd",
"_spec": "jweixin-module",
"_where": "D:\\diaoyun\\花园\\garden_merchant",
"author": {
"name": "Shengqiang Guo"
},
"bugs": {
"url": "https://github.com/zhetengbiji/jweixin-module/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "微信JS-SDK",
"devDependencies": {},
"homepage": "https://github.com/zhetengbiji/jweixin-module#readme",
"keywords": [
"wxjssdk",
"weixin",
"jweixin",
"wechat",
"jssdk",
"wx"
],
"license": "ISC",
"main": "lib/index.js",
"name": "jweixin-module",
"repository": {
"type": "git",
"url": "git+https://github.com/zhetengbiji/jweixin-module.git"
},
"scripts": {},
"version": "1.6.0"
}
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"jweixin-module": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/jweixin-module/-/jweixin-module-1.6.0.tgz",
"integrity": "sha512-dGk9cf+ipipHmtzYmKZs5B2toX+p4hLyllGLF6xuC8t+B05oYxd8fYoaRz0T30U2n3RUv8a4iwvjhA+OcYz52w=="
}
}
}
const erp = erp || {};
//const DOMAIN = 'https://dev.diaosaas.com/car/';
// const DOMAIN='https://diaosaas.com/car/'
// const DOMAIN='https://dev.diaosaas.com/partyHistory/'//测试
const DOMAIN='https://faces.diaosaas.com/garden/'//正式
// const DOMAIN = 'http://192.168.1.198:9095/';
//const DOMAIN = 'http://192.168.1.163:8089/';
//const DOMAIN ='http://47.110.68.2/car/'
//const HOST = '/api' + 'api/';
const HOST = DOMAIN + 'api/';
erp.login = HOST + 'wechat/login' //登录
erp.getOpenId = HOST + 'wechat/getOpenId' //微信授权获取openId
erp.number = HOST + 'user/number' //个人信息比赛次数
erp.addMatch = HOST + 'user/addMatch' //比赛提交数据
erp.getLearnAndMatch = HOST + 'subject/getLearnAndMatch' //获取题目
erp.rand = HOST + 'subject/rand' //获取排行榜
erp.myRand = HOST + 'user/rand' //获取个人排名
erp.sign = HOST + 'sign/list' //获取签名时间戳
export default erp;
const http = ({
url = '',
params = {},
...other
} = {}) => {
let time = Date.now()
return new Promise((resolve, reject) => {
let token = uni.getStorageSync("token");
uni.request({
url: url,
data: params,
header: {
'token': token,
'content-type': 'application/json' // 默认值
},
...other,
success: (res) => {
if (res.data.code == 500 && res.data.msg == '用户不存在') {
uni.showModal({
content: '登录已过期 请重新登录',
showCancel: false,
success(res) {
if (res.confirm) {
uni.reLaunch({
url: '/pages/login/login'
})
} else if (res.cancel) {
uni.reLaunch({
url: '/pages/login/login'
})
}
}
})
}
if (res.data.code == 402) {
uni.reLaunch({
url: '/pages/login/login'
})
}
if (res.data.code == 401 || res.data.code == 403) {
uni.showModal({
content: '登录已过期 请重新登录',
showCancel: false,
success(res) {
if (res.confirm) {
uni.reLaunch({
url: '/pages/login/login'
})
} else if (res.cancel) {
uni.reLaunch({
url: '/pages/login/login'
})
}
}
})
resolve(res.data)
}
if (res.data.code == 200) {
resolve(res.data)
} else {
resolve(res.data)
//uni.showToast({ title: '无法请求接口', icon: 'none', duration: 2000 })
reject(res)
}
},
fail: (err) => {
uni.hideLoading();
console.log(err)
}
})
})
}
module.exports = {
get(url, params = {}) {
return http({
url,
params
})
},
post(url, params = {}) {
return http({
url,
params,
header: {
"Content-Type": "application/json"
},
method: 'post'
})
},
apost(url, params = {}) {
return http({
url,
params,
header: {
"Content-Type": "application/json"
},
method: 'post'
})
},
put(url, params = {}) {
return http({
url,
params,
method: 'put'
})
},
// 这里不能使用 delete, delete为关键字段
myDelete(url, params = {}) {
return http({
url,
params,
method: 'delete'
})
},
/**
* 优惠券有效期
* startDate:起始日期
* valueTime:有效天数
*/
transferCouponValueTime(startDate, valueTime) {
var date = new Date(startDate);
var newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() + valueTime);
var year1 = date.getFullYear();
var month1 = date.getMonth() + 1;
var day1 = date.getDate();
var year2 = newDate.getFullYear();
var month2 = newDate.getMonth() + 1;
var day2 = newDate.getDate();
return year2 + "/" + month2 + "/" + day2
},
//获取时间
getDate(type) {
const date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
if (type === 'start') {
year = year - 60;
} else if (type === 'end') {
year = year + 2;
}
month = month > 9 ? month : '0' + month;;
day = day > 9 ? day : '0' + day;
return `${year}-${month}-${day}`;
},
// 转换为'00:00:00'
getDuration(my_time) {
if (my_time <= 0) {
return '0'
} else {
var days = my_time / 1000 / 60 / 60 / 24;
var daysRound = Math.floor(days);
var hours = my_time / 1000 / 60 / 60 - (24 * daysRound);
var hoursRound = Math.floor(hours) < 10 ? '0' + Math.floor(hours) : Math.floor(hours);
var minutes = my_time / 1000 / 60 - (24 * 60 * daysRound) - (60 * hoursRound);
var minutesRound = Math.floor(minutes) < 10 ? '0' + Math.floor(minutes) : Math.floor(minutes);
var seconds = my_time / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 *
minutesRound);
var secondsRound = Math.floor(seconds) < 10 ? '0' + Math.floor(seconds) : Math.floor(seconds)
// console.log('转换时间:', hoursRound + '时', minutesRound + '分', seconds + '秒');
// this.remaincutdown = hoursRound + ':' + minutesRound + ':' + seconds
var time = daysRound + '天' + hoursRound + ':' + minutesRound + ':' + secondsRound
return time
}
},
// 获取当前时间
getpresenttime() {
var date = new Date(),
year = date.getFullYear(),
month = date.getMonth() + 1,
day = date.getDate(),
hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
month >= 1 && month <= 9 ? (month = "0" + month) : "";
day >= 0 && day <= 9 ? (day = "0" + day) : "";
var timer = year + '/' + month + '/' + day + ' ' + hour + ':' + minute + ':' + second;
return timer;
},
//获取当前往后十年list
getyearlist() {
var date = new Date()
var year = date.getFullYear()
let yearlist = []
for (var i = 0; i < 10; i++) {
let years = year + i
yearlist.push(years)
}
return yearlist
},
// 获取前后年份
getNearbyFiveears() {
let year = new Date().getFullYear()
let arr = []
for (var i = 0; i < 5; i++) {
let year1 = year - i + 1;
let year2 = year + i;
arr.push(year1)
arr.push(year2)
}
arr.sort((a, b) => {
return a - b
})
let yearArr = arr.map((item, index) => {
let obj = {}
obj.label = item
obj.value = index + 1
return obj
})
yearArr.unshift({
label: '全部',
value: 0
})
return yearArr
},
// 获取当前时间
getYearmomthday() {
var date = new Date(),
year = date.getFullYear(),
month = date.getMonth() + 1,
day = date.getDate(),
hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
month >= 1 && month <= 9 ? (month = "0" + month) : "";
day >= 0 && day <= 9 ? (day = "0" + day) : "";
var timer = year + '/' + month + '/' + day;
return timer;
},
//自定义加法运算
addNum(num1, num2) {
var sq1, sq2, m;
try {
sq1 = num1.toString().split(".")[1].length;
} catch (e) {
sq1 = 0;
}
try {
sq2 = num2.toString().split(".")[1].length;
} catch (e) {
sq2 = 0;
}
m = Math.pow(10, Math.max(sq1, sq2));
return (num1 * m + num2 * m) / m;
},
accMul(arg1, arg2) {
var m = 0,
s1 = arg1.toString(),
s2 = arg2.toString();
try {
m += s1.split(".")[1].length
} catch (e) {}
try {
m += s2.split(".")[1].length
} catch (e) {}
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
},
}
async function compressImage(src, platform) {
const imageInfo = await getImageInfo(src);
const orientation = imageInfo.orientation;
let rotate = 0;
let quality = 80;
if (platform === 'ios') {
rotate = 0;
quality = 25;
} else {
switch (orientation) {
case 'up': //exif:1 不旋转
rotate = 0;
break;
case 'down': //exif:3 旋转180度
rotate = 180;
break;
case 'right': //exif:6 旋转90度
rotate = 90;
break;
case 'left': //exif:8 旋转270度
rotate = 270;
break;
default:
rotate = 0;
break;
}
}
return new Promise(function(resolve, reject) {
plus.zip.compressImage({
src: src,
dst: "_doc/uniapp_temp" + '/compressed/' + Math.round(new Date()) + '.jpg',
format: 'jpg',
quality: quality,
width: 'auto',
height: 'auto',
rotate: rotate,
},
function(event) {
let tempPath = event.target;
resolve(tempPath)
},
function(error) {
reject(error);
});
})
}
function getImageInfo(path) {
return new Promise(function(resolve, reject) {
// #ifdef APP-PLUS
plus.io.getImageInfo({
src: path,
success: function(image) {
// console.log(image.width);
// console.log(image.height);
// console.log('orientation=' + image.orientation);
// console.log('path=' + image.path);
resolve(image)
},
fail: function(err) {
console.log("getImageInfoErr: " + JSON.stringify(err));
reject(err)
}
});
// #endif
// #ifdef H5 || MP-WEIXIN
uni.getImageInfo({
src: path,
success: function(image) {
// console.log(image.width);
// console.log(image.height);
// console.log('orientation=' + image.orientation);
// console.log('path=' + image.path);
resolve(image)
},
fail: function(err) {
console.log("getImageInfoErr: " + JSON.stringify(err));
reject(err)
}
});
// #endif
});
}
export default compressImage
\ No newline at end of file
const get = (url, data, callBack) => {
uni.request({
url: url,
data: data,
method: 'GET',
header: {
'content-type': 'application/json;charset=utf-8' // 默认值
},
complete: function(res) {
callBack(res)
// console.log(res)
}
})
}
// 防抖
const antiShake = function antiSahake(fn) {
let timeId = null
console.log('防抖')
return function(fn) {
debugger
if (timeId) {
console.log('点击多次')
clearTimeout(timeId)
}
timeId = setTimeout(fn, 10000)
}
}
module.exports = {
get: get,
antiShake: antiShake,
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论