doum
2 天以前 b29d7b6bbe8256d5e95fb878adf06ffa9abb449a
web/pages/index/index.vue
@@ -1,5 +1,5 @@
<template>
   <view class="content">
   <view class="content" v-if="validPath">
      <view class="banner">
         <image src="/static/banner.png" mode="widthFix"></image>
      </view>
@@ -38,6 +38,10 @@
      </view>
      <view class="btn" @click="sendSave">去支付</view>
   </view>
   <view class="box" v-else>
      <image src="/static/ic_payfail.png" mode="widthFix" class="icon"></image>
      <view class="title" >请使用微信或者支付宝应用扫码打开</view>
   </view>
</template>
<script>
@@ -46,6 +50,7 @@
      data() {
         return {
            flag:'name',
            validPath : true,
            form: {
               type: 0,
               name: '',
@@ -53,13 +58,32 @@
               money: '',
               remark: '',
               userId:''
            }
            },
            loading:false
         }
      },
      mounted() {
         this.loading=false
         this.validPath = this.isWeChatBrowser() || this.isAlipayBrowser()
         this.form.userId = this.fetchParams("userId",window.location.href)
      },
      methods: {
         // 判断是否在微信浏览器中打开
         isWeChatBrowser() {
           // #ifdef H5
           const userAgent = navigator.userAgent.toLowerCase();
           return userAgent.indexOf('micromessenger') !== -1;
           // #endif
           return false;
         },
         // 判断是否在支付宝浏览器中打开
         isAlipayBrowser() {
           // #ifdef H5
           const userAgent = navigator.userAgent.toLowerCase();
           return userAgent.indexOf('alipayclient') !== -1;
           // #endif
           return false;
         },
         toSuccess() {
            uni.navigateTo({
               url: '/pages/success/success'
@@ -75,17 +99,30 @@
            return decodeURIComponent(results[2].replace(/\+/g, ' '));
         },
         async sendSave() {
            if(this.loading){
               // return
            }
            this.loading=true
            var that = this
            if(!this.form.name){
               uni.showToast({
                  'title': '请输入姓名',icon:'none'
               })
               this.loading=false
               return
            }
            if(!this.form.phone){
               uni.showToast({
                  'title': '请输入手机号',icon:'none'
               })
               this.loading=false
               return
            }
            if(this.form.phone.length != 11){
               uni.showToast({
                  'title': '请输入正确的11位手机号',icon:'none'
               })
               this.loading=false
               return
            }
            if(!this.form.money || this.form.money < 0.01){
@@ -95,21 +132,15 @@
               return
            }
            let res = await this.$u.api.orderCreate(this.form)
            if (res.code === 200) {
            if (res && res.code === 200) {
                const url = res.data.url
                // axios.post('https://third-party-website.com/api/submit', this.formData, {
                //   headers: { 'Content-Type': 'application/json' } // 根据需要添加其他头部信息,如认证令牌等。
                // })
                // axios.post(res.data.url, res.data.params);
               // const resolve = this.$router.push(url,params);
               // window.open(resolve.href, "_blank")
                console.log(res)
                const elements = document.querySelectorAll('form');
                if(elements&& elements.length){
                   elements.forEach(element => {
                       element.remove();
                   })
                }
                uni.showToast({title:'发起支付中'})
                var demo_form = document.createElement("form");
                  demo_form.action = url;
                  demo_form.id = "tempFromId";
@@ -128,19 +159,36 @@
                     }
                  }
                  document.body.appendChild(demo_form)
                  uni.showToast({
                     'title': '特挑剔',icon:'none'
                  })
                  demo_form.submit() 
                  
               // this.toSuccess()
            }
            }
            this.loading=false
         },
      }
   }
</script>
<style lang="scss" scoped>
   .box {
      width: 100%;
      padding: 0 40rpx;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      .icon {
         width: 180rpx;
         height: 180rpx;
         margin-top: 54rpx;
      }
      .title {
         font-size: 32rpx;
         color: #222222;
         margin-top: 32rpx;
      }
   }
   .content {
      width: 100%;
      padding: 20rpx 30rpx;
@@ -223,7 +271,7 @@
                  width: 100%;
                  font-weight: 400;
                  font-size: 28rpx;
                  color: #999999;
                  //color: #999999;
                  text-align: right;
               }
            }