Commit 3d06e205 authored by 郭志伟's avatar 郭志伟

fix: pay联调

parent e6840ba1
...@@ -4,11 +4,16 @@ ...@@ -4,11 +4,16 @@
<div class="loading-container" v-show="isLoading"> <div class="loading-container" v-show="isLoading">
<cr-loading class="loading" size="24px">加载中...</cr-loading> <cr-loading class="loading" size="24px">加载中...</cr-loading>
</div> </div>
<login-modal />
</div> </div>
</template> </template>
<script> <script>
import { mapState, mapActions } from "vuex"; import { mapState, mapActions } from "vuex";
import LoginModal from "@/components/LoginModal";
export default { export default {
components: {
LoginModal
},
computed: { computed: {
...mapState(["isLoading"]) ...mapState(["isLoading"])
}, },
...@@ -22,7 +27,6 @@ export default { ...@@ -22,7 +27,6 @@ export default {
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@import "./style/index.less"; @import "./style/index.less";
.loading-container { .loading-container {
position: fixed; position: fixed;
left: 0; left: 0;
......
...@@ -3,15 +3,45 @@ ...@@ -3,15 +3,45 @@
v-model="show" v-model="show"
title="您好<br />欢迎来到芒果保险" title="您好<br />欢迎来到芒果保险"
:closeable="true" :closeable="true"
cancel-btn="" cancel-btn
confirm-btn="确定" confirm-btn="确定"
@confirm="login"
> >
<cr-form
class="login-form"
ref="loginForm"
validate-trigger="onBlur"
@submit="onFormSubmit"
@failed="onFormFailed"
>
<cr-field
v-model="formData.phoneNo"
name="phoneNo"
type="tel"
label="手机号"
placeholder="请填写您的手机号"
:rules="validOptions[0]"
/>
<cr-field
v-model="formData.verifyCode"
name="verifyCode"
type="tel"
label="验证码"
placeholder="请填写验证码"
:rules="validOptions[1]"
>
<template v-slot:button>
<a href="javascript:;">获取验证码</a>
<span class="login-form-remain">59s</span>
</template>
</cr-field>
</cr-form>
</modal> </modal>
</template> </template>
<script> <script>
import Modal from "@/components/Modal"; import Modal from "@/components/Modal";
import { loginByPhone } from "@/api/user";
import { isPhone } from "@/service/validation";
export default { export default {
name: "LoginModal", name: "LoginModal",
components: { components: {
...@@ -19,18 +49,65 @@ export default { ...@@ -19,18 +49,65 @@ export default {
}, },
data() { data() {
return { return {
show: false show: false,
formData: {
phoneNo: "",
verifyCode: ""
},
validOptions: [
[
{ require: true, message: "请填写您的手机号" },
{ validator: isPhone, message: "手机号格式错误" }
],
[{ require: true, message: "请填写验证码" }]
]
}; };
}, },
watch: { methods: {
value(val) { onFormSubmit() {
this.show = val; this.login();
}
}, },
methods: {} onFormFailed(errorInfo) {
const { errors } = errorInfo;
this.$notify({ type: "warning", message: errors[0].message });
},
async login() {
this.formData.loginChannel = 1;
this.formData.openId = 1;
const res = await loginByPhone(this.formData);
if (res.code === 0) {
this.$notify("登录成功");
}
}
}
}; };
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@import "../../../../style/var.less"; @import "../style/var.less";
.login-form {
@{deep} .cr-field--error-message {
display: none;
}
@{deep} .cr-cell {
&-group {
&::after {
display: none;
}
}
background-color: @gray-1;
border-radius: @border-radius-md;
margin-bottom: 12px;
align-items: center;
padding: 9px 16px;
&::after {
display: none;
}
&__title {
color: #333333;
display: flex;
align-items: center;
}
}
}
</style> </style>
export default { export default {
// basicHost: "https://hathaway-mg.liangkebang.net/", basicHost: "https://hathaway-mg.liangkebang.net/",
basicHost: "http://127.0.0.1:8964/",
wxAppId: "wx514de17b23d53a20" wxAppId: "wx514de17b23d53a20"
}; };
import Vue from "vue"; import Vue from "vue";
import "@/service/load";
import App from "./App.vue"; import App from "./App.vue";
import router from "./router"; import router from "./router";
import store from "./store"; import store from "./store";
...@@ -6,7 +7,6 @@ import "./style/index.less"; ...@@ -6,7 +7,6 @@ import "./style/index.less";
import "amfe-flexible"; import "amfe-flexible";
// import vConsole from "vconsole"; // import vConsole from "vconsole";
import "@/assets/icons/index"; import "@/assets/icons/index";
import "@/service/load";
import "@/service/cherry-ui"; import "@/service/cherry-ui";
Vue.config.productionTip = false; Vue.config.productionTip = false;
......
//引入axios //引入axios
import store from "@/store"; import store from "@/store";
import axios from "axios"; import axios from "axios";
import cherry from "@qg/cherry-ui"; import { Notify } from "@qg/cherry-ui";
import config from "../config"; import config from "../config";
// import qs from "qs"; // import qs from "qs";
const CancelToken = axios.CancelToken; const CancelToken = axios.CancelToken;
const { Notify } = cherry; // const { Notify } = cherry;
axios.defaults.baseURL = config.basicHost; axios.defaults.baseURL = config.basicHost;
axios.defaults.timeout = 30000; axios.defaults.timeout = 30000;
...@@ -53,7 +53,7 @@ axios.interceptors.response.use( ...@@ -53,7 +53,7 @@ axios.interceptors.response.use(
response => { response => {
afterRequest(); afterRequest();
delete pending[response.config.url]; delete pending[response.config.url];
if (response.data.code === 0) { if (response.data.code === "0") {
return response.data; return response.data;
// return response.data.data; // return response.data.data;
} }
......
/**
* 时间转换
* @param {String} time 需要转换的时间
* @param {String} cFormat 格式 {y}-{m}-{d} {h}:{i}:{s}
* @return: {String} timeStr 转换完成的时间
*/
export function parseTime(time, cFormat) {
if (arguments.length === 0) {
return "-";
}
if (time == null) {
return "-";
}
const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
let date;
if (time == "") {
date = new Date();
} else if (typeof time === "object") {
date = time;
} else {
if (("" + time).length === 10) time = parseInt(time) * 1000;
if (String(time).indexOf("T") > -1) {
time = time.replace(/T/g, " ").replace(/\..*/g, "");
}
if (String(time).indexOf("-") > -1 && String(time).indexOf("T") == -1) {
time = time.replace(/-/g, "/");
}
date = new Date(time);
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
};
const timeStr = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key];
if (key === "a") {
return ["", "", "", "", "", "", ""][value];
}
if (result.length > 0 && value < 10) {
value = "0" + value;
}
return value || 0;
});
return timeStr;
}
/**
* 时间显示效果显示
* @param {String} time 需要转换的时间
* @param {String} option 格式 {y}-{m}-{d} {h}:{i}:{s}
* @return: {String} 转换完成的时间
*/
export function formatTime(time, option) {
time = +time * 1000;
const d = new Date(time);
const now = Date.now();
const diff = (now - d) / 1000;
if (diff < 30) {
return "刚刚";
} else if (diff < 3600) {
// less 1 hour
return Math.ceil(diff / 60) + "分钟前";
} else if (diff < 3600 * 24) {
return Math.ceil(diff / 3600) + "小时前";
} else if (diff < 3600 * 24 * 2) {
return "1天前";
}
if (option) {
return parseTime(time, option);
} else {
return (
d.getMonth() + 1 + "" + d.getDate() + "" + d.getHours() + "" + d.getMinutes() + ""
);
}
}
/**
* 延时函数
* @param {Function} func 方法
* @param {Number} wait 等待时间
* @param {Boolean} immediate 是否立即执行
* @return: {Function} result 方法执行
*/
export function debounce(func, wait, immediate) {
let timeout, args, context, timestamp, result;
const later = function() {
// 据上一次触发时间间隔
const last = +new Date() - timestamp;
// 上次被包装函数被调用时间间隔last小于设定时间间隔wait
if (last < wait && last > 0) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
if (!immediate) {
result = func.apply(context, args);
if (!timeout) context = args = null;
}
}
};
return function(...args) {
context = this;
timestamp = +new Date();
const callNow = immediate && !timeout;
// 如果延时不存在,重新设定延时
if (!timeout) timeout = setTimeout(later, wait);
if (callNow) {
result = func.apply(context, args);
context = args = null;
}
return result;
};
}
/** /**
* 替换邮箱字符 * 替换邮箱字符
* @param {String} email 输入字符串 * @param {String} email 输入字符串
......
...@@ -23,7 +23,6 @@ import GoodList from "@/components/GoodList/index"; ...@@ -23,7 +23,6 @@ import GoodList from "@/components/GoodList/index";
import Tabbar from "@/components/Tabbar"; import Tabbar from "@/components/Tabbar";
import copyright from "@/components/Copyright"; import copyright from "@/components/Copyright";
import RecordLayer from "@/components/RecordLayer"; import RecordLayer from "@/components/RecordLayer";
export default { export default {
name: "GoodsList", name: "GoodsList",
components: { components: {
......
...@@ -128,7 +128,7 @@ export default { ...@@ -128,7 +128,7 @@ export default {
methods: { methods: {
async login() { async login() {
const res = await loginByPhone(this.loginInfo); const res = await loginByPhone(this.loginInfo);
if (res.code === 0) { if (res.code === "0") {
this.mongoToken = res.data.token; this.mongoToken = res.data.token;
localStorage.setItem("mongoToken", res.data.token); localStorage.setItem("mongoToken", res.data.token);
} }
...@@ -148,7 +148,7 @@ export default { ...@@ -148,7 +148,7 @@ export default {
if (this.openId) return; if (this.openId) return;
const code = this.$route.query.code; const code = this.$route.query.code;
const res = await getwxOpenId({ code, appId: cfg.wxAppId }); const res = await getwxOpenId({ code, appId: cfg.wxAppId });
if (res.code === 0) { if (res.code === "0") {
this.openId = res.data.openId; this.openId = res.data.openId;
localStorage.setItem("openId", res.data.openId); localStorage.setItem("openId", res.data.openId);
} }
...@@ -168,7 +168,7 @@ export default { ...@@ -168,7 +168,7 @@ export default {
} }
this.tradeType = tradeType; this.tradeType = tradeType;
const res = await placeOrder.create(this.insuredOrderInfo); const res = await placeOrder.create(this.insuredOrderInfo);
if (res.code === 0) { if (res.code === "0") {
this.orderInfo = res.data; this.orderInfo = res.data;
} }
}, },
...@@ -180,7 +180,7 @@ export default { ...@@ -180,7 +180,7 @@ export default {
return; return;
} }
const res = await placeOrder.pay({ payOrderNo, payType, tradeType }); const res = await placeOrder.pay({ payOrderNo, payType, tradeType });
if (res.code === 0) { if (res.code === "0") {
let payInfo = { let payInfo = {
url: res.data.payUrl, url: res.data.payUrl,
params: { params: {
...@@ -202,7 +202,7 @@ export default { ...@@ -202,7 +202,7 @@ export default {
pollTimer = setTimeout(() => { pollTimer = setTimeout(() => {
const { payOrderNo, payType } = this.orderInfo; const { payOrderNo, payType } = this.orderInfo;
placeOrder.polling({ payOrderNo, payType }).then(res => { placeOrder.polling({ payOrderNo, payType }).then(res => {
if (res.code === 0) { if (res.code === "0") {
const { result, payState } = res.data; const { result, payState } = res.data;
if (result) { if (result) {
this.$toast("支付成功"); this.$toast("支付成功");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment