提交 b9f8a36a authored 作者: lihuihui's avatar lihuihui
......@@ -4,11 +4,12 @@ module.exports = {
// apiBaseURL: 'https://zy2.ezijing.com/',
webpack: {
externals: {
CKEDITOR: 'window.CKEDITOR',
Base64: 'window.Base64',
md5: 'window.md5',
regeneratorRuntime: 'window.regeneratorRuntime',
wx: 'window.wx'
'CKEDITOR': 'window.CKEDITOR',
'Base64': 'window.Base64',
'md5': 'window.md5',
'regeneratorRuntime': 'window.regeneratorRuntime',
'wx': 'window.wx',
'WeixinJSBridge': 'window.WeixinJSBridge'
},
devServer: {
proxy: {
......
......@@ -8,7 +8,9 @@ module.exports = {
'CKEDITOR': 'window.CKEDITOR',
'Base64': 'window.Base64',
'md5': 'window.md5',
'regeneratorRuntime': 'window.regeneratorRuntime'
'regeneratorRuntime': 'window.regeneratorRuntime',
'wx': 'window.wx',
'WeixinJSBridge': 'window.WeixinJSBridge'
}
},
ProvidePlugin: {
......
......@@ -8,7 +8,9 @@ module.exports = {
'CKEDITOR': 'window.CKEDITOR',
'Base64': 'window.Base64',
'md5': 'window.md5',
'regeneratorRuntime': 'window.regeneratorRuntime'
'regeneratorRuntime': 'window.regeneratorRuntime',
'wx': 'window.wx',
'WeixinJSBridge': 'window.WeixinJSBridge'
}
},
ProvidePlugin: {
......
......@@ -18,6 +18,7 @@
"$": false,
"window": false,
"webConf": false,
"wx": false
"wx": false,
"WeixinJSBridge": false
}
}
......@@ -2,9 +2,11 @@
/* 模块基于 element-ui,一定在 element-ui后加载 */
import ExamModule from './exam-module'
import PayModule from './pay-module'
const components = [
ExamModule
ExamModule,
PayModule
]
const install = function (Vue, opts = {}) {
......@@ -20,5 +22,6 @@ if (typeof window !== 'undefined' && window.Vue) {
export default {
install,
ExamModule
ExamModule,
PayModule
}
import BaseACTION from '@/action/base_action'
import { Pay } from '../api'
export default class PayAction extends BaseACTION {
getOrderId(obj) {
return Pay.getOrderId(obj).then(res => res)
}
}
import PayAction from './PayAction'
const Pay = new PayAction()
export default Pay
import PayAPI from './pay_api'
const Pay = new PayAPI(webConf)
export {
Pay
}
import BaseAPI from '@/api/base_api'
export default class Pay extends BaseAPI {
getOrderId = (obj) => this.post('/v2/mall/order/pre', obj, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } })
}
{
"PayModule": {
"DiscussList": {
"answers": "Answers",
"votes": "Votes",
"noData": "No discussion"
},
"DiscussDetail": {
"title": "Problem details",
"like": "Like",
"discuss": "Discuss",
"reply": "Reply",
"delete": "Delete",
"send": "Send",
"noAnswer": "No answer",
"deleteSuccess": "Delete success",
"answering": "Answer"
}
}
}
import Cookies from 'js-cookie'
import VueI18n from 'vue-i18n'
import language from './language'
// import zhCNLocale from 'element-ui/lib/locale/lang/zh-CN'
// import enLocale from 'element-ui/lib/locale/lang/en'
export default () => {
let _locale = 'zh-CN'
/* 国际化初始化 */
const _defaultLocale = 'zh-CN'
const _lang = Cookies.get('lang') || window.navigator.language || window.navigator.userLanguage || ''
if (_lang) {
if (language[_lang]) {
_locale = _lang
} else {
let flag = true
/* 做一下 兼容性处理 */
for (const k in language) {
const reg = new RegExp(k, 'gi')
if (reg.test(_lang)) {
_locale = k
flag = false
break
}
}
if (flag) {
/* 当前语言版本 - 不再我们的语言库中,那么默认 en */
_locale = _defaultLocale
Cookies.set('lang', _defaultLocale, { expires: 30, domain: '.ezijing.com' })
}
}
}
return new VueI18n({
locale: _locale, // 定义默认语言为中文
messages: {
'zh-CN': Object.assign(require('./zh-CN.json')),
en: Object.assign(require('./en.json'))
}
})
}
/* 定义语言模型 - key 值定义 跟 languages i18n 中 保持一致 */
const language = {
'zh-CN': { show: '语言', arr: [{ 'zh-CN': '中文' }, { en: 'English' }] },
en: { show: 'Language', arr: [{ 'zh-CN': '中文' }, { en: 'English' }] }
}
export default language
{
"PayModule": {
"DiscussList": {
"answers": "回答",
"votes": "投票",
"noData": "暂无相关评论"
},
"DiscussDetail": {
"title": "问题详情",
"like": "点赞",
"discuss": "讨论",
"reply": "回复",
"delete": "删除",
"send": "发送",
"noAnswer": "暂无回答",
"deleteSuccess": "删除成功",
"answering": "回答问题"
}
}
}
import './index.scss'
import PayH5 from './src/PayH5.vue'
const components = [
PayH5
]
const install = function (Vue, opts = {}) {
/* 存在国际化 */
if (opts.i18n) {
const msgs = opts.i18n.messages
for (const k in msgs) {
opts.i18n.setLocaleMessage(k, Object.assign(msgs[k], require('./assets/languages/' + k + '.json')))
}
}
components.forEach(component => {
Vue.component(component.name, component)
})
}
/* istanbul ignore if */
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue)
}
export default {
install,
PayH5
}
/* Extra small devices (portrait phones, less than 576px) */
@media (max-width: 575px) {}
/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767px) {}
/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991px) {}
/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) and (max-width: 1199px) {}
/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {}
<template>
<!-- 暂时无用 -->
<div class="pay-box"></div>
</template>
<script>
import Pay from '../action'
export default {
name: 'PayH5',
components: {},
data () {
const _this = this
return {
isCard: false,
opaKey: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
remainingTime: '01:00:00',
currentNum: 1,
isAnalysis: false,
swiperOptions: {
observer: true,
on: {
slideChangeTransitionStart: function() {
document.getElementById('bottom-view').scrollTop = 0
_this.isAnalysis = false
_this.currentNum = this.activeIndex + 1
}
}
},
questionsData: {
questions: []
},
requestData: {},
requestData2: {},
clockCount: null,
isExamEnd: true,
// examIsShow: false,
isExamSubPop: false,
timePopIsShow: false,
initTime: null,
cache: null
}
},
props: {
requestParam: {
type: Object,
required: false,
default () {
return {
product_id: '', // 提前设定
open_id: '', // 通过微信授权获取
prepay_id: '', // 通过调用接口获取
app_id: '', // 提前设定
app_secret: '' // 提前设定
}
}
}
},
beforeDestroy() {
},
mounted () {
/* 判别是否引入JSSDK */
// if (typeof WeixinJSBridge === 'undefined') {
// console.log('尚未引入微信JSSDK或JSSDK未执行')
// if (document.addEventListener) {
// document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady.bind(this), false)
// } else if (document.attachEvent) {
// document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady.bind(this))
// document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady.bind(this))
// }
// } else {
// this.onBridgeReady()
// }
this.onBridgeReady()
},
methods: {
onBridgeReady () {
this.VueEvent.$off('pay-wx-h5').$on('pay-wx-h5', (obj) => {
const _callback = obj.callback || function () {}
const _obj = this.goToPay()
_callback(_obj)
})
},
goToPay () {
const obj = { code: 0, msg: '', data: {} }
if (!this.requestParam.product_id) {
obj.code = 3001
obj.msg = '没有商品ID'
return obj
}
if (!this.requestParam.open_id) {
obj.code = 3002
obj.msg = '没有小程序用户openid'
return obj
}
return Pay.getOrderId(this.requestParam).then(res => {
obj.data = res
this.wxWakeUpToPay()
// return
}).catch(e => {
obj.code = 5001
obj.msg = e.message
return obj
})
},
wxWakeUpToPay () {
/* 直接调用微信支付 */
const timestamp = parseInt(new Date().getTime() / 1000)
const noncestr = parseInt(Math.random() * 10000000000000000)
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
appId: this.requestParam.app_id, // 公众号名称,由商户传入
timeStamp: timestamp + '', // 时间戳,自1970年以来的秒数
nonceStr: noncestr + '', // 随机串
package: 'prepay_id=' + this.requestParam.prepay_id,
signType: 'MD5', // 微信签名方式:
paySign: '70EA570631E4BB79628FBCA90534C63FF7FADD89' // 微信签名
},
function (res) {
if (res.err_msg === 'get_brand_wcpay_request:ok') {
// 使用以上方式判断前端返回,微信团队郑重提示:
// res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
}
}
)
}
}
}
</script>
<style lang="scss">
</style>
......@@ -98,7 +98,7 @@ export default {
})
},
// 登录成功
loginSuccess(response) {
loginSuccess(response, delta = 2) {
if (response.code === 0) {
Cookies.remove('wechat_login_error', { domain: '.ezijing.com' })
Cookies.remove('wechat_login_no_phone_error', {
......@@ -107,7 +107,7 @@ export default {
this.$store.commit('setToken', response.data.TGC)
if (this.isWeapp) {
wx.miniProgram.postMessage({ data: { token: response.data.TGC } })
wx.miniProgram.navigateBack({ delta: 2 })
wx.miniProgram.navigateBack({ delta })
return
}
if (this.redirectURI) {
......@@ -140,7 +140,7 @@ export default {
beforeMount() {
this.$store.dispatch('checkLogin').then(isLogin => {
if (isLogin) {
this.loginSuccess({ code: 0, data: { TGC: Cookies.get('TGC') } })
this.loginSuccess({ code: 0, data: { TGC: Cookies.get('TGC') } }, 1)
} else {
if (this.isWechat && !this.checkWechatLogin()) {
this.wechatLogin()
......
<template>
<div>
<van-button type="primary">默认按钮</van-button>
<van-button type="primary" @click="goPay">默认按钮</van-button>
<pay-h5 :requestParam="requestParam"></pay-h5>
</div>
</template>
<script>
......@@ -10,6 +11,13 @@ export default {
},
data() {
return {
requestParam: {
product_id: '', // 提前设定
open_id: '', // 通过微信授权获取
prepay_id: '', // 通过调用接口获取
app_id: '', // 提前设定
app_secret: '' // 提前设定
}
}
},
mounted() {
......@@ -27,6 +35,14 @@ export default {
// api.getGoodsDetails('6682927830365372416').then(res => {
// console.log(res)
// })
},
goPay () {
this.VueEvent.$emit('pay-wx-h5', {
data: {},
callback: function (obj) {
console.log(obj)
}
})
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论