第一次提交
This commit is contained in:
249
core/app.js
Executable file
249
core/app.js
Executable file
@@ -0,0 +1,249 @@
|
||||
import store from '@/store'
|
||||
import * as util from '@/utils/util'
|
||||
import {
|
||||
paginate
|
||||
} from '@/common/constant'
|
||||
import Config from './config'
|
||||
|
||||
/**
|
||||
* 显示成功提示框
|
||||
*/
|
||||
export const showSuccess = (msg, callback) => {
|
||||
uni.showToast({
|
||||
title: msg,
|
||||
icon: 'success',
|
||||
mask: true,
|
||||
duration: 1500,
|
||||
success() {
|
||||
callback && callback()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示失败提示框
|
||||
*/
|
||||
export const showError = (msg, callback) => {
|
||||
uni.showModal({
|
||||
title: '友情提示',
|
||||
content: msg,
|
||||
showCancel: false,
|
||||
success(res) {
|
||||
callback && callback()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示纯文字提示框
|
||||
*/
|
||||
export const showToast = (msg, duration = 1500, mask = true) => {
|
||||
uni.showToast({
|
||||
title: msg, // 提示的内容
|
||||
icon: 'none',
|
||||
mask, // 是否显示透明蒙层,防止触摸穿透
|
||||
duration // 提示的延迟时间,单位毫秒,默认:1500
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* tabBar页面路径列表 (用于链接跳转时判断)
|
||||
* tabBarLinks为常量, 无需修改
|
||||
*/
|
||||
export const getTabBarLinks = () => {
|
||||
const tabBarLinks = [
|
||||
'pages/index/index',
|
||||
'pages/zone/zone',
|
||||
'pages/love/love',
|
||||
'pages/notice/notice',
|
||||
'pages/user/user'
|
||||
]
|
||||
return tabBarLinks
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成完整的H5地址 [带参数]
|
||||
* @param {string} baseUrl H5访问地址
|
||||
* @param {string} path 页面路径
|
||||
* @param {object} params 页面参数
|
||||
* @return {string}
|
||||
*/
|
||||
export const buildUrL = (h5Url, path, params) => {
|
||||
let complete = h5Url
|
||||
if (!util.isEmpty(path)) {
|
||||
complete += '#/' + path
|
||||
const shareParamsStr = getShareUrlParams(params)
|
||||
if (!util.isEmpty(shareParamsStr)) {
|
||||
complete += '?' + shareParamsStr
|
||||
}
|
||||
}
|
||||
return complete
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成转发的url参数(string格式)
|
||||
* @param {object} params
|
||||
* @return {string}
|
||||
*/
|
||||
export const getShareUrlParams = params => {
|
||||
return util.urlEncode(getShareParams(params))
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成转发的url参数(object格式)
|
||||
* @param {object} params
|
||||
* @return {object}
|
||||
*/
|
||||
export const getShareParams = params => {
|
||||
return {
|
||||
refereeId: store.getters.userId, // 推荐人ID
|
||||
...params
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到指定页面url
|
||||
* 支持tabBar页面
|
||||
* @param {string} url 页面路径
|
||||
* @param {object} query 页面参数
|
||||
* @param {string} modo 跳转类型(默认navigateTo)
|
||||
*/
|
||||
export const navTo = (url, query = {}, modo = 'navigateTo') => {
|
||||
if (!url || url.length == 0) {
|
||||
return false
|
||||
}
|
||||
// tabBar页面, 使用switchTab
|
||||
if (util.inArray(url, getTabBarLinks())) {
|
||||
uni.switchTab({
|
||||
url: `/${url}`
|
||||
})
|
||||
return true
|
||||
}
|
||||
// 生成query参数
|
||||
const queryStr = !util.isEmpty(query) ? '?' + util.urlEncode(query) : ''
|
||||
// 普通页面, 使用navigateTo
|
||||
modo === 'navigateTo' && uni.navigateTo({
|
||||
url: `/${url}${queryStr}`
|
||||
})
|
||||
// 特殊指定, 使用redirectTo
|
||||
modo === 'redirectTo' && uni.redirectTo({
|
||||
url: `/${url}${queryStr}`
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前页面数据
|
||||
* @param {object}
|
||||
*/
|
||||
export const getCurrentPage = () => {
|
||||
const pages = getCurrentPages()
|
||||
const {
|
||||
route,
|
||||
options
|
||||
} = pages[pages.length - 1]
|
||||
return {
|
||||
path: route,
|
||||
query: options
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取购物车商品总数量
|
||||
* @param {*} value
|
||||
*/
|
||||
export const getCartTotalNum = (value) => {
|
||||
const cartTotal = uni.getStorageSync('cartTotalNum') || 0
|
||||
return checkLogin() ? cartTotal : 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录购物车商品总数量
|
||||
* @param {*} value
|
||||
*/
|
||||
export const setCartTotalNum = (value) => {
|
||||
uni.setStorageSync('cartTotalNum', Number(value))
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置购物车tabbar的角标
|
||||
* 该方法只能在tabbar页面中调用, 其他页面调用会报错
|
||||
*/
|
||||
export const setCartTabBadge = () => {
|
||||
const cartTabbarIndex = 2
|
||||
const cartTotal = getCartTotalNum()
|
||||
if (cartTotal > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: cartTabbarIndex,
|
||||
text: `${cartTotal}`
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: cartTabbarIndex
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否已登录
|
||||
*/
|
||||
export const checkLogin = () => {
|
||||
return !!store.getters.userId
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载更多列表数据
|
||||
* @param {Object} resList 新列表数据
|
||||
* @param {Object} oldList 旧列表数据
|
||||
* @param {int} pageNo 当前页码
|
||||
*/
|
||||
export const getEmptyPaginateObj = () => {
|
||||
return util.cloneObj(paginate)
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载更多列表数据
|
||||
* @param {Object} resList 新列表数据
|
||||
* @param {Object} oldList 旧列表数据
|
||||
* @param {int} pageNo 当前页码
|
||||
*/
|
||||
export const getMoreListData = (resList, oldList, pageNo) => {
|
||||
// 如果是第一页需手动制空列表
|
||||
if (pageNo == 1) oldList.data = []
|
||||
// 合并新数据
|
||||
return oldList.data.concat(resList.data)
|
||||
}
|
||||
|
||||
/**
|
||||
* scene解码
|
||||
* 用于解码微信小程序二维码参数,并返回对象
|
||||
*/
|
||||
export const sceneDecode = (str) => {
|
||||
if (str === undefined)
|
||||
return {}
|
||||
const data = {}
|
||||
const params = decodeURIComponent(str).split(',')
|
||||
for (const i in params) {
|
||||
const val = params[i].split(':');
|
||||
val.length > 0 && val[0] && (data[val[0]] = val[1] || null)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取二维码场景值(scene)
|
||||
*/
|
||||
export const getSceneData = (query) => {
|
||||
return query.scene ? sceneDecode(query.scene) : {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 路由跳转
|
||||
*/
|
||||
export const routePush = (url, params) => {
|
||||
return uni.$u.route({
|
||||
url,
|
||||
params
|
||||
})
|
||||
}
|
||||
20
core/bootstrap.js
vendored
Executable file
20
core/bootstrap.js
vendored
Executable file
@@ -0,0 +1,20 @@
|
||||
import store from '@/store'
|
||||
import storage from '@/utils/storage'
|
||||
import Config from '@/core/config'
|
||||
import platform from '@/core/platform'
|
||||
import { ACCESS_TOKEN, USER_ID, REFEREE_ID, APP_THEME } from '@/store/mutation-types'
|
||||
|
||||
export default function Initializer() {
|
||||
// 当前的商城ID
|
||||
store.commit('SET_STORE_ID', Config.getStoreId())
|
||||
// 当前运行的终端
|
||||
store.commit('SET_PLATFORM', platform)
|
||||
// 用户认证token
|
||||
store.commit('SET_TOKEN', storage.get(ACCESS_TOKEN))
|
||||
// 当前用户ID
|
||||
store.commit('SET_USER_ID', storage.get(USER_ID))
|
||||
// 当前推荐人ID
|
||||
store.commit('SET_REFEREE_ID', storage.get(REFEREE_ID))
|
||||
// 全局自定义主题
|
||||
store.commit('SET_APP_THEME', storage.get(APP_THEME))
|
||||
}
|
||||
46
core/config/defaultConfig.js
Executable file
46
core/config/defaultConfig.js
Executable file
@@ -0,0 +1,46 @@
|
||||
// ** 本文件是config.js的默认数据 (请勿修改本文件中的内容)
|
||||
// ** 如需修改配置请移步到根目录的config.js文件
|
||||
export default {
|
||||
|
||||
// 系统名称
|
||||
name: "WebSoftApp",
|
||||
|
||||
/**
|
||||
* 后端api地址 (必填; 斜杠/结尾; 请确保能访问)
|
||||
* 例如: https://www.你的域名.com/index.php?s=/api/
|
||||
*/
|
||||
apiUrl: "https://open.gxwebsoft.com/api",
|
||||
|
||||
/**
|
||||
* 商城ID (必填)
|
||||
* 可在超管后台-商城列表中查看
|
||||
*/
|
||||
storeId: 10001,
|
||||
|
||||
// 租户ID
|
||||
tenantId: 10048,
|
||||
|
||||
/**
|
||||
* 是否启用商城设置缓存
|
||||
* 将减少用户端重复请求; 正式运营时请设为true, 开启后商城设置同步前端需10分钟缓存
|
||||
*/
|
||||
enabledSettingCache: true,
|
||||
|
||||
/**
|
||||
* 是否开启APP端的微信分享功能
|
||||
* 如果开启, 需配置manifest.json中 APP模块配置 -> Share(分享) -> 微信分享
|
||||
*/
|
||||
enabledAppShareWeixin: false,
|
||||
|
||||
/**
|
||||
* 是否启用H5端多开
|
||||
* 启用后将通过获取子域名中的ID作为storeId; 例如域名是 "shop10001.baidu.com", 那么storeId就是10001
|
||||
*/
|
||||
enabledH5Multi: false,
|
||||
|
||||
/**
|
||||
* 获取子域名ID的正则
|
||||
*/
|
||||
domainIdRegex: /shop[\-]?(\d+)\./
|
||||
|
||||
}
|
||||
54
core/config/index.js
Executable file
54
core/config/index.js
Executable file
@@ -0,0 +1,54 @@
|
||||
import config from '@/config.js'
|
||||
import defaultConfig from './defaultConfig.js'
|
||||
|
||||
// 合并用户配置和默认配置
|
||||
const options = Object.assign({}, defaultConfig, config)
|
||||
|
||||
/**
|
||||
* 配置文件工具类
|
||||
* @module Config
|
||||
* mix: 如需在项目中获取配置项, 请使用本工具类的方法, 不要直接import根目录的config.js
|
||||
*/
|
||||
export default {
|
||||
|
||||
/**
|
||||
* 获取全部配置
|
||||
*/
|
||||
all() {
|
||||
return options
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取指定配置
|
||||
* @param {string} key
|
||||
* @param {mixed} def
|
||||
*/
|
||||
get(key, def = undefined) {
|
||||
if (options.hasOwnProperty(key)) {
|
||||
return options[key]
|
||||
}
|
||||
console.error(`检测到不存在的配置项: ${key}`)
|
||||
return def
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取当前商城ID
|
||||
*/
|
||||
getStoreId() {
|
||||
|
||||
// #ifdef H5
|
||||
// 判断是否启用H5端多开
|
||||
// 启用后将通过获取子域名中的ID作为storeId
|
||||
if (this.get('enabledH5Multi')) {
|
||||
const domain = window.location.hostname
|
||||
const regex = this.get('domainIdRegex')
|
||||
if (domain.match(regex)) {
|
||||
const storeId = regex.exec(domain)[1].trim()
|
||||
return storeId
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
return this.get('storeId')
|
||||
},
|
||||
|
||||
}
|
||||
40
core/mixins/app.js
Executable file
40
core/mixins/app.js
Executable file
@@ -0,0 +1,40 @@
|
||||
import Vue from 'vue'
|
||||
import { mapGetters } from 'vuex'
|
||||
import store from '@/store/index'
|
||||
import platform from '@/core/platform'
|
||||
|
||||
// 字符串驼峰转中划线
|
||||
const formatToLine = value => {
|
||||
return value.replace(/([A-Z])/g, '-$1').toLowerCase()
|
||||
}
|
||||
|
||||
// 主题样式 (因小程序端不支持styleObject语法,所以需要转换成字符串)
|
||||
const appTheme2Str = appTheme => {
|
||||
let str = ''
|
||||
for (const index in appTheme) {
|
||||
const name = formatToLine(index)
|
||||
str += `--${name}:${appTheme[index]};`
|
||||
}
|
||||
return str
|
||||
}
|
||||
import dayjs from "dayjs"
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
platform
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['appTheme']),
|
||||
appThemeStyle() {
|
||||
const appTheme = store.getters.appTheme
|
||||
return appTheme2Str(appTheme)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
computedAge(birthday){
|
||||
return dayjs().diff(dayjs(birthday), 'year')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
72
core/mixins/notice.js
Normal file
72
core/mixins/notice.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import {
|
||||
mapGetters
|
||||
} from 'vuex'
|
||||
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
pageActive: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['conversations','unReadMessageCount', 'unReadCommentNumber']),
|
||||
},
|
||||
watch: {
|
||||
unReadMessageCount(val) {
|
||||
if (this.pageActive) {
|
||||
this.setTabbar()
|
||||
}
|
||||
},
|
||||
unReadCommentNumber(val){
|
||||
if (this.pageActive) {
|
||||
this.setPyqTabbar()
|
||||
}
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.pageActive = true;
|
||||
this.setTabbar()
|
||||
},
|
||||
onHide() {
|
||||
this.pageActive = false;
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 设置tabbar的未读消息数量
|
||||
*/
|
||||
setTabbar() {
|
||||
|
||||
if (this.unReadMessageCount > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: 3,
|
||||
text: this.unReadMessageCount + '',
|
||||
fail: (err) => {
|
||||
console.log("unReadCount: ", err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: 3
|
||||
})
|
||||
}
|
||||
},
|
||||
setPyqTabbar() {
|
||||
console.log("this.unReadCommentNumber: ",this.unReadCommentNumber);
|
||||
if (this.unReadCommentNumber > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: 2,
|
||||
text: this.unReadCommentNumber + '',
|
||||
fail: (err) => {
|
||||
console.log("unReadCount: ", err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: 2
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
73
core/mixins/tabbar.js
Normal file
73
core/mixins/tabbar.js
Normal file
@@ -0,0 +1,73 @@
|
||||
import {
|
||||
mapGetters
|
||||
} from 'vuex'
|
||||
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
pageActive: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['conversations','unReadMessageCount', 'unReadCommentNumber', 'conversationArr','unReadLikeNumber','unReadLikeMeNumber','unReadLookNumber']),
|
||||
},
|
||||
watch: {
|
||||
unReadMessageCount(val) {
|
||||
if (this.pageActive) {
|
||||
this.setTabbar()
|
||||
}
|
||||
},
|
||||
unReadCommentNumber(val){
|
||||
if (this.pageActive) {
|
||||
this.setPyqTabbar()
|
||||
}
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.pageActive = true;
|
||||
this.setTabbar()
|
||||
this.setPyqTabbar()
|
||||
},
|
||||
onHide() {
|
||||
this.pageActive = false;
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 设置tabbar的未读消息数量
|
||||
*/
|
||||
setTabbar() {
|
||||
|
||||
if (this.unReadMessageCount > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: 2,
|
||||
text: this.unReadMessageCount + '',
|
||||
fail: (err) => {
|
||||
console.log("unReadCount: ", err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: 2
|
||||
})
|
||||
}
|
||||
},
|
||||
setPyqTabbar() {
|
||||
console.log("this.unReadCommentNumber: ",this.unReadCommentNumber);
|
||||
if (this.unReadCommentNumber > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: 1,
|
||||
text: this.unReadCommentNumber + '',
|
||||
fail: (err) => {
|
||||
console.log("unReadCount: ", err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: 1
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
91
core/payment/alipay.js
Executable file
91
core/payment/alipay.js
Executable file
@@ -0,0 +1,91 @@
|
||||
import platform from '@/core/platform'
|
||||
import ClientEnum from '@/common/enum/Client'
|
||||
import { PayMethodEnum } from '@/common/enum/payment'
|
||||
|
||||
/**
|
||||
* 发起支付请求 (用于H5)
|
||||
* @param {Object} option 参数
|
||||
*/
|
||||
const paymentAsH5 = option => {
|
||||
const options = { formHtml: '', ...option }
|
||||
// 跳转到支付宝支付页
|
||||
return new Promise((resolve, reject) => {
|
||||
// console.log(options.formHtml)
|
||||
if (options.formHtml) {
|
||||
const div = document.createElement('div')
|
||||
div.innerHTML = options.formHtml
|
||||
document.body.appendChild(div)
|
||||
document.forms[0].submit()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付请求 (用于APP)
|
||||
* @param {Object} option 参数
|
||||
*/
|
||||
const paymentAsApp = options => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.requestPayment({
|
||||
provider: 'alipay',
|
||||
orderInfo: options.orderInfo,
|
||||
success(res) {
|
||||
// isRequireQuery 是否需要主动查单
|
||||
// outTradeNo 交易订单号
|
||||
const option = {
|
||||
isRequireQuery: true,
|
||||
outTradeNo: options.out_trade_no,
|
||||
method: 'alipay'
|
||||
}
|
||||
resolve({ res, option })
|
||||
},
|
||||
fail: res => reject(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 获取支付完成后跳转的url
|
||||
// #ifdef H5
|
||||
const returnUrl = () => {
|
||||
return window.location.href
|
||||
}
|
||||
// #endif
|
||||
|
||||
/**
|
||||
* 统一下单API
|
||||
*/
|
||||
export const payment = (option) => {
|
||||
const events = {
|
||||
[ClientEnum.H5.value]: paymentAsH5,
|
||||
[ClientEnum.APP.value]: paymentAsApp
|
||||
}
|
||||
return events[platform](option)
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一下单API需要的扩展数据
|
||||
*/
|
||||
export const extraAsUnify = () => {
|
||||
const extra = {}
|
||||
// #ifdef H5
|
||||
extra.returnUrl = returnUrl()
|
||||
// #endif
|
||||
return extra
|
||||
}
|
||||
|
||||
// H5端支付宝支付下单时的数据
|
||||
// 用于从支付宝支付页返回到收银台页面后拿到下单数据
|
||||
// #ifdef H5
|
||||
export const performance = () => {
|
||||
const query = getCurrentQuery()
|
||||
if (query.method && query.method === 'alipay.trade.wap.pay.return') {
|
||||
return { method: PayMethodEnum.ALIPAY.value, outTradeNo: query.out_trade_no }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const getCurrentQuery = () => {
|
||||
const pages = getCurrentPages()
|
||||
return pages[pages.length - 1].$route.query
|
||||
}
|
||||
// #endif
|
||||
4
core/payment/index.js
Executable file
4
core/payment/index.js
Executable file
@@ -0,0 +1,4 @@
|
||||
import * as Alipay from './alipay'
|
||||
import * as Wechat from './wechat'
|
||||
|
||||
export { Alipay, Wechat }
|
||||
180
core/payment/wechat.js
Normal file
180
core/payment/wechat.js
Normal file
@@ -0,0 +1,180 @@
|
||||
import platform from '@/core/platform'
|
||||
import storage from '@/utils/storage'
|
||||
import ClientEnum from '@/common/enum/Client'
|
||||
import { PayMethodEnum } from '@/common/enum/payment'
|
||||
|
||||
/**
|
||||
* 发起支付请求 (用于微信小程序)
|
||||
* @param {Object} option 参数
|
||||
*/
|
||||
const paymentAsWxMp = option => {
|
||||
const options = {
|
||||
timeStamp: '',
|
||||
nonceStr: '',
|
||||
package: '',
|
||||
signType: '',
|
||||
paySign: '',
|
||||
...option
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
timeStamp: options.timeStamp,
|
||||
nonceStr: options.nonceStr,
|
||||
package: options.package,
|
||||
signType: options.signType,
|
||||
paySign: options.paySign,
|
||||
success(res) {
|
||||
const option = {
|
||||
isRequireQuery: true, // 是否需要主动查单
|
||||
outTradeNo: options.out_trade_no, // 交易订单号
|
||||
method: 'wechat'
|
||||
}
|
||||
resolve({ res, option })
|
||||
},
|
||||
fail: res => reject(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付请求 (用于H5)
|
||||
* @param {Object} option 参数
|
||||
*/
|
||||
const paymentAsH5 = option => {
|
||||
const options = { orderKey: null, mweb_url: '', h5_url: '', ...option }
|
||||
// 记录下单的信息
|
||||
storage.set('tempUnifyData_' + options.orderKey, {
|
||||
method: PayMethodEnum.WECHAT.value,
|
||||
outTradeNo: options.out_trade_no
|
||||
}, 60 * 60)
|
||||
// 跳转到微信支付页
|
||||
return new Promise((resolve, reject) => {
|
||||
const url = options.mweb_url || options.h5_url
|
||||
if (url) {
|
||||
window.location.href = url
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付请求 (用于微信公众号)
|
||||
* @param {Object} option 参数
|
||||
*/
|
||||
const paymentAsOfficial = option => {
|
||||
const options = {
|
||||
appId: '',
|
||||
timeStamp: '',
|
||||
nonceStr: '',
|
||||
package: '',
|
||||
signType: '',
|
||||
paySign: '',
|
||||
...option
|
||||
}
|
||||
return onBridgeReady(options)
|
||||
if (platform === ClientEnum.H5_WEIXIN.value) {
|
||||
if (typeof WeixinJSBridge != 'undefined') {
|
||||
return onBridgeReady(options)
|
||||
}
|
||||
if (document.addEventListener) {
|
||||
document.addEventListener('WeixinJSBridgeReady', () => onBridgeReady(options), false)
|
||||
} else if (document.attachEvent) {
|
||||
document.attachEvent('WeixinJSBridgeReady', () => onBridgeReady(options))
|
||||
document.attachEvent('onWeixinJSBridgeReady', () => onBridgeReady(options))
|
||||
}
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
reject({ message: '当前不支持WeixinJSBridge11' })
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付请求 (用于APP)
|
||||
* @param {Object} option 参数
|
||||
*/
|
||||
const paymentAsApp = options => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
orderInfo: {
|
||||
partnerid: options.partnerid,
|
||||
appid: options.appid,
|
||||
package: 'Sign=WXPay',
|
||||
noncestr: options.noncestr,
|
||||
sign: options.sign,
|
||||
prepayid: options.prepayid,
|
||||
timestamp: options.timestamp
|
||||
},
|
||||
success(res) {
|
||||
// isRequireQuery 是否需要主动查单
|
||||
// outTradeNo 交易订单号
|
||||
resolve({ res, option: { isRequireQuery: true, outTradeNo: options.out_trade_no, method: 'wechat' } })
|
||||
},
|
||||
fail: res => reject(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 微信公众号调用微信支付
|
||||
// #ifdef H5
|
||||
const onBridgeReady = (options) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
WeixinJSBridge.invoke(
|
||||
'getBrandWCPayRequest', {
|
||||
appId: options.appId,
|
||||
timeStamp: options.timeStamp,
|
||||
nonceStr: options.nonceStr,
|
||||
package: options.package,
|
||||
signType: options.signType,
|
||||
paySign: options.paySign,
|
||||
},
|
||||
res => {
|
||||
if (res.err_msg == "get_brand_wcpay_request:ok") {
|
||||
const option = {
|
||||
isRequireQuery: true, // 是否需要主动查单
|
||||
outTradeNo: options.out_trade_no, // 交易订单号
|
||||
method: 'wechat'
|
||||
}
|
||||
resolve({ res, option })
|
||||
} else {
|
||||
reject(res)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
// #endif
|
||||
|
||||
/**
|
||||
* 统一下单API
|
||||
*/
|
||||
export const payment = (option) => {
|
||||
const events = {
|
||||
[ClientEnum.H5.value]: paymentAsH5,
|
||||
[ClientEnum.MP_WEIXIN.value]: paymentAsWxMp,
|
||||
[ClientEnum.H5_WEIXIN.value]: paymentAsOfficial,
|
||||
[ClientEnum.APP.value]: paymentAsApp
|
||||
}
|
||||
return events[platform](option)
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一下单API需要的扩展数据
|
||||
*/
|
||||
export const extraAsUnify = () => {
|
||||
return {}
|
||||
}
|
||||
|
||||
// H5端微信支付下单时的数据
|
||||
// 用于从微信支付页返回到收银台页面后拿到下单数据
|
||||
// #ifdef H5
|
||||
export const performance = (orderKey) => {
|
||||
if (window.performance && window.performance.navigation.type == 2) {
|
||||
const tempUnifyData = storage.get('tempUnifyData_' + orderKey)
|
||||
if (tempUnifyData) {
|
||||
storage.remove('tempUnifyData_' + orderKey)
|
||||
return tempUnifyData
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
// #endif
|
||||
64
core/platform.js
Executable file
64
core/platform.js
Executable file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* 获取当前运行的客户端(APP H5 小程序)
|
||||
* https://uniapp.dcloud.io/platform
|
||||
*/
|
||||
const getPlatform = () => {
|
||||
// #ifdef APP-PLUS
|
||||
const platform = 'APP'
|
||||
// #endif
|
||||
// #ifdef APP-PLUS-NVUE
|
||||
const platform = 'APP'
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
const platform = weixinOfficial() ? 'H5-WEIXIN' : 'H5'
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
const platform = 'MP-WEIXIN'
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
const platform = 'MP-ALIPAY'
|
||||
// #endif
|
||||
// #ifdef MP-BAIDU
|
||||
const platform = 'MP-BAIDU'
|
||||
// #endif
|
||||
// #ifdef MP-TOUTIAO
|
||||
const platform = 'MP-TOUTIAO'
|
||||
// #endif
|
||||
// #ifdef MP-LARK
|
||||
const platform = 'MP-LARK'
|
||||
// #endif
|
||||
// #ifdef MP-QQ
|
||||
const platform = 'MP-QQ'
|
||||
// #endif
|
||||
// #ifdef MP-KUAISHOU
|
||||
const platform = 'MP-KUAISHOU'
|
||||
// #endif
|
||||
// #ifdef MP-360
|
||||
const platform = 'MP-360'
|
||||
// #endif
|
||||
// #ifdef QUICKAPP-WEBVIEW
|
||||
const platform = 'QUICKAPP-WEBVIEW'
|
||||
// #endif
|
||||
return platform
|
||||
}
|
||||
|
||||
// 是否为微信公众号端
|
||||
const weixinOfficial = () => {
|
||||
// #ifdef H5
|
||||
const ua = window.navigator.userAgent.toLowerCase()
|
||||
return String(ua.match(/MicroMessenger/i)) === 'micromessenger'
|
||||
// #endif
|
||||
return false
|
||||
}
|
||||
|
||||
const platfrom = getPlatform()
|
||||
|
||||
export const isH5 = platfrom === 'H5'
|
||||
export const isApp = platfrom === 'APP'
|
||||
export const isMpWeixin = platfrom === 'MP-WEIXIN'
|
||||
|
||||
// 是否为微信公众号端
|
||||
// 相当于H5端运行在微信内置浏览器, 但是需要使用微信的jssdk所以要单独区分
|
||||
export const isWeixinOfficial = platfrom === 'H5-WEIXIN'
|
||||
|
||||
export default platfrom
|
||||
Reference in New Issue
Block a user