123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /* 小程序码 */
- import store from '@/store/index.js'
- import { wxUnlimited } from '@/services/api/auth.js'
- const fs = uni.getFileSystemManager()
- const qrcodePath = `${wx.env.USER_DATA_PATH}/qrcodePath`
- const defalutOptions = {
- title: '护肤上颜选,正品有好货~',
- path: '/pages/index/index',
- imageUrl: 'https://static.caimei365.com/app/mini-hehe/icon/icon-share.png'
- }
- export function shareDataResult(shareData, title, coverUrl) {
- const state_str = encodeURIComponent(encrypt(shareData))
- const result = {
- title: title || defalutOptions.title,
- path: `${defalutOptions.path}?state_str=${state_str}`,
- imageUrl: coverUrl || defalutOptions.imageUrl
- }
- return result
- }
- const queryKeyOfMap = {
- 'type': 't',
- 'inviteUserId': 'i',
- 'activityId': 'a',
- 'dealerUserId': 'd',
- 'keyWord': 'k',
- 'productId': 'p',
- 'jumpState': 'j',
- 'collageId': 'c'
- }
- const enQueryKeyOfMap = {
- 't': 'type',
- 'i': 'inviteUserId',
- 'a': 'activityId',
- 'd': 'dealerUserId',
- 'k': 'keyWord',
- 'p': 'productId',
- 'j': 'jumpState',
- 'c': 'collageId'
- }
- // 创建二维码保存路径
- function createQrcodeDir(callback) {
- try {
- fs.accessSync(qrcodePath)
- console.log('已存在文件夹')
- callback(qrcodePath)
- } catch (e) {
- fs.mkdirSync(qrcodePath)
- console.log('不存在文件夹')
- callback(qrcodePath)
- }
- }
- /* 生成二维码链接 */
- export async function generateWxUnlimited(params) {
- try {
- // 从服务端获取二维码arrayBuffer
- return await wxUnlimited({
- page: params.pagePath || 'pages/index/index',
- scene: codeQueryStr(params.queryStr),
- check_path: process.env.NODE_ENV === 'production', // 是否校验页面
- env_version: process.env.NODE_ENV === 'production' ? 'release' : 'trial', // 正式版 or 开发版
- width: 200, // 二维码宽度
- auto_color: false, // 自动颜色
- line_color: { 'r': 0, 'g': 0, 'b': 0 }, // 线条颜色
- is_hyaline: true // 透明底
- })
- } catch (e) {
- return Promise.reject(e)
- }
- }
- // 编码查询参数
- export function codeQueryStr(query = '') {
- const keys = Object.keys(queryKeyOfMap)
- return query.split('&').map(str => {
- return str.split('=').map((substr, index) => {
- if (!index) {
- return queryKeyOfMap[keys.find(item => substr === item)]
- } else {
- return substr
- }
- }).join('=')
- }).join('&')
- }
- // 反编码查询参数
- export function enCodeQueryStr(query) {
- const keys = Object.keys(enQueryKeyOfMap)
- return query.split('&').map(str => {
- return str.split('=').map((substr, index) => {
- if (!index) {
- return enQueryKeyOfMap[keys.find(item => substr === item)]
- } else {
- return substr
- }
- }).join('=')
- }).join('&')
- }
|