123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- import {
- BrowseRecordAdd
- } from '@/api/applist.js'
- import sha256 from 'crypto-js/sha256'
- //防抖函数
- export function debounce(func, fnThis, wait) {
- var timer;
- return () => {
- timer && clearTimeout(timer);
- timer = setTimeout(() => {
- func.call(fnThis)
- timer = null
- }, wait);
- };
- }
- //节流函数
- export function throttling(func, fnThis, wait) {
- var timer;
- return () => {
- clearTimeout(timer);
- timer = setTimeout(func.bind(fnThis), wait);
- };
- }
- let goMiniAppFlag = false
- //跳转小程序
- export function goMiniApp(data, item) {
- if (goMiniAppFlag) return
- goMiniAppFlag = true
- let myData = JSON.parse(data)
- wx.navigateToMiniProgram({
- ...myData,
- success: (res) => {
- // 打开成功
- goMiniAppFlag = false
- item && BrowseRecordAdd(item.id)
- },
- fail: () => {
- goMiniAppFlag = false
- }
- })
- }
- //跳转页面
- export function goPage(url, type, data) {
- if (type == 'reLaunch') {
- uni.reLaunch({
- url
- });
- return
- }
- if (type == 'redirectTo') {
- uni.redirectTo({
- url
- });
- return
- }
- uni.navigateTo({
- url,
- success: function(res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('passParameters', data)
- }
- });
- }
- //接受参数
- export function goPageGetData() {
- return new Promise((res) => {
- const eventChannel = this.getOpenerEventChannel()
- eventChannel.on('passParameters', function(data) {
- res(data)
- })
- })
- }
- //根据类型跳转
- export function clickJumpType(item) {
- if (item.jumpUrlType == 'goMiniApp') {
- goMiniApp(item.jumpUrl)
- }
- if (item.jumpUrlType == 'goPage') {
- goPage(item.jumpUrl)
- }
- if (item.jumpUrlType == 'goWebView') {
- goPage(`/pages/webview/webview?src=${item.jumpUrl}`)
- }
- }
- function base64_encode(str) {
- var c1, c2, c3;
- var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- var i = 0,
- len = str.length,
- string = '';
- while (i < len) {
- c1 = str.charCodeAt(i++) & 0xff;
- if (i == len) {
- string += base64EncodeChars.charAt(c1 >> 2);
- string += base64EncodeChars.charAt((c1 & 0x3) << 4);
- string += "==";
- break;
- }
- c2 = str.charCodeAt(i++);
- if (i == len) {
- string += base64EncodeChars.charAt(c1 >> 2);
- string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
- string += base64EncodeChars.charAt((c2 & 0xF) << 2);
- string += "=";
- break;
- }
- c3 = str.charCodeAt(i++);
- string += base64EncodeChars.charAt(c1 >> 2);
- string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
- string += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
- string += base64EncodeChars.charAt(c3 & 0x3F)
- }
- return string
- }
- //微信支付调起支付
- export function wxPay(data) {
- wx.requestPayment({
- ...data
- })
- }
- //返回星期几
- export function getUTCDay(date) {
- let UTCDay = new Date(date).getUTCDay()
- switch (UTCDay) {
- case 0:
- return '周天';
- case 1:
- return '周一';
- case 2:
- return '周二';
- case 3:
- return '周三';
- case 4:
- return '周四';
- case 5:
- return '周五';
- case 6:
- return '周六';
- }
- }
- //返回今天明天后天周几
- export function getDay(date) {
- let UTCDay = new Date(date).getUTCDay()
- let jetLag = new Date(date).getTime() - new Date().getTime()
- let dayDif = jetLag / (1000 * 60 * 60 * 24)
- if (dayDif < 2) {
- if (dayDif < 0) {
- return '今天'
- }
- if (dayDif < 1) {
- return '明天'
- }
- if (dayDif < 2) {
- return '后天'
- }
- }
- switch (UTCDay) {
- case 0:
- return '周天';
- case 1:
- return '周一';
- case 2:
- return '周二';
- case 3:
- return '周三';
- case 4:
- return '周四';
- case 5:
- return '周五';
- case 6:
- return '周六';
- }
- }
- export default {
- goPageGetData,
- clickJumpType,
- debounce,
- throttling,
- goMiniApp,
- goPage,
- wxPay,
- getUTCDay,
- getDay
- }
|