Selaa lähdekoodia

Merge branch 'dev' of http://113.31.163.91:7777/quanshu/mp-ui-pc into dev

Liugl 3 vuotta sitten
vanhempi
commit
dd4e97190f

+ 202 - 0
public/jump-mp.html

@@ -0,0 +1,202 @@
+<html>
+  <head>
+    <title>打开小程序</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
+    <script>
+      window.onerror = e => {
+        console.error(e)
+        alert('发生错误' + e)
+      }
+    </script>
+    <!-- weui 样式 -->
+    <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.1/weui.min.css"></link>
+    <!-- 调试用的移动端 console -->
+    <!-- <script src="https://cdn.jsdelivr.net/npm/eruda"></script> -->
+    <!-- <script>eruda.init();</script> -->
+    <!-- 公众号 JSSDK -->
+    <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
+    <!-- 云开发 Web SDK -->
+    <script src="https://res.wx.qq.com/open/js/cloudbase/1.1.0/cloud.js"></script>
+    <script>
+      function docReady(fn) {
+        if (document.readyState === 'complete' || document.readyState === 'interactive') {
+          fn()
+        } else {
+          document.addEventListener('DOMContentLoaded', fn);
+        }
+      }
+
+      docReady(async function() {
+        var ua = navigator.userAgent.toLowerCase()
+        var isWXWork = ua.match(/wxwork/i) == 'wxwork'
+        var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
+        var isMobile = false
+        var isDesktop = false
+        if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
+          isMobile = true
+        } else {
+          isDesktop = true
+        }
+
+        if (isWeixin) {
+          var containerEl = document.getElementById('wechat-web-container')
+          containerEl.classList.remove('hidden')
+          containerEl.classList.add('full', 'wechat-web-container')
+
+          var launchBtn = document.getElementById('launch-btn')
+          launchBtn.addEventListener('ready', function (e) {
+            console.log('开放标签 ready')
+          })
+          launchBtn.addEventListener('launch', function (e) {
+            console.log('开放标签 success')
+          })
+          launchBtn.addEventListener('error', function (e) {
+            console.log('开放标签 fail', e.detail)
+          })
+
+          wx.config({
+            // debug: true, // 调试时可开启
+            appId: '小程序 AppID', // <!-- replace -->
+            timestamp: 0, // 必填,填任意数字即可
+            nonceStr: 'nonceStr', // 必填,填任意非空字符串即可
+            signature: 'signature', // 必填,填任意非空字符串即可
+            jsApiList: ['chooseImage'], // 必填,随意一个接口即可 
+            openTagList:['wx-open-launch-weapp'], // 填入打开小程序的开放标签名
+          })
+        } else if (isDesktop) {
+          // 在 pc 上则给提示引导到手机端打开
+          var containerEl = document.getElementById('desktop-web-container')
+          containerEl.classList.remove('hidden')
+          containerEl.classList.add('full', 'desktop-web-container')
+        }  else {
+          var containerEl = document.getElementById('public-web-container')
+          containerEl.classList.remove('hidden')
+          containerEl.classList.add('full', 'public-web-container')
+          var c = new cloud.Cloud({
+            // 必填,表示是未登录模式
+            identityless: true,
+            // 资源方 AppID
+            resourceAppid: '小程序 AppID', // <!-- replace -->
+            // 资源方环境 ID
+            resourceEnv: '云开发环境 ID', // <!-- replace -->
+          })
+          await c.init()
+          window.c = c
+
+          var buttonEl = document.getElementById('public-web-jump-button')
+          var buttonLoadingEl = document.getElementById('public-web-jump-button-loading')
+          try {
+            await openWeapp(() => {
+              buttonEl.classList.remove('weui-btn_loading')
+              buttonLoadingEl.classList.add('hidden')
+            })
+          } catch (e) {
+            buttonEl.classList.remove('weui-btn_loading')
+            buttonLoadingEl.classList.add('hidden')
+            throw e
+          }
+        }
+      })
+
+      async function openWeapp(onBeforeJump) {
+        var c = window.c
+        const res = await c.callFunction({
+          name: 'public',
+          data: {
+            action: 'getUrlScheme',
+          },
+        })
+        console.warn(res)
+        if (onBeforeJump) {
+          onBeforeJump()
+        }
+        location.href = res.result.openlink
+      }
+    </script>
+    <style>
+      .hidden {
+        display: none;
+      }
+
+      .full {
+        position: absolute;
+        top: 0;
+        bottom: 0;
+        left: 0;
+        right: 0;
+      }
+
+      .public-web-container {
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+      }
+
+      .public-web-container p {
+        position: absolute;
+        top: 40%;
+      }
+
+      .public-web-container a {
+        position: absolute;
+        bottom: 40%;
+      }
+
+      .wechat-web-container {
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+      }
+
+      .wechat-web-container p {
+        position: absolute;
+        top: 40%;
+      }
+
+      .wechat-web-container wx-open-launch-weapp {
+        position: absolute;
+        bottom: 40%;
+        left: 0;
+        right: 0;
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+      }
+
+      .desktop-web-container {
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+      }
+
+      .desktop-web-container p {
+        position: absolute;
+        top: 40%;
+      }
+    </style>
+  </head>
+  <body>
+    <div class="page full">
+      <div id="public-web-container" class="hidden">
+        <p class="">正在打开 “填入你的小程序名称”...</p> <!-- replace -->
+        <a id="public-web-jump-button" href="javascript:" class="weui-btn weui-btn_primary weui-btn_loading" onclick="openWeapp()">
+          <span id="public-web-jump-button-loading" class="weui-primary-loading weui-primary-loading_transparent"><i class="weui-primary-loading__dot"></i></span>
+          打开小程序
+        </a>
+      </div>
+      <div id="wechat-web-container" class="hidden">
+        <p class="">点击以下按钮打开 “填入你的小程序名称”</p> <!-- replace -->
+        <!-- 跳转小程序的开放标签。文档 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html -->
+        <wx-open-launch-weapp id="launch-btn" username="小程序原始账号 ID(gh_ 开头的)" path="要跳转到的页面路径"> <!-- replace -->
+          <template>
+            <button style="width: 200px; height: 45px; text-align: center; font-size: 17px; display: block; margin: 0 auto; padding: 8px 24px; border: none; border-radius: 4px; background-color: #07c160; color:#fff;">打开小程序</button>
+          </template>
+        </wx-open-launch-weapp>
+      </div>
+      <div id="desktop-web-container" class="hidden">
+        <p class="">请在手机打开网页链接</p>
+      </div>
+    </div>
+  </body>
+</html>

+ 239 - 0
public/jump.html

@@ -0,0 +1,239 @@
+<html>
+
+<head>
+  <title>打开小程序</title>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
+  <script>
+    window.onerror = e => {
+      console.error(e)
+      alert('发生错误' + e)
+    }
+  </script>
+  <!-- weui 样式 -->
+  <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.1/weui.min.css">
+  </link>
+  <!-- 调试用的移动端 console -->
+  <!-- <script src="https://cdn.jsdelivr.net/npm/eruda"></script> -->
+  <!-- <script>eruda.init();</script> -->
+  <!-- 公众号 JSSDK -->
+  <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
+  <!-- 云开发 Web SDK -->
+  <script src="https://res.wx.qq.com/open/js/cloudbase/1.1.0/cloud.js"></script>
+  <script>
+    function docReady(fn) {
+      if (document.readyState === 'complete' || document.readyState === 'interactive') {
+        fn()
+      } else {
+        document.addEventListener('DOMContentLoaded', fn);
+      }
+    }
+
+    docReady(async function () {
+      var ua = navigator.userAgent.toLowerCase()
+      var isWXWork = ua.match(/wxwork/i) == 'wxwork'
+      var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
+      var isMobile = false
+      var isDesktop = false
+      if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
+        isMobile = true
+      } else {
+        isDesktop = true
+      }
+
+      if (isWeixin) {
+        var containerEl = document.getElementById('wechat-web-container')
+        containerEl.classList.remove('hidden')
+        containerEl.classList.add('full', 'wechat-web-container')
+
+        var launchBtn = document.getElementById('launch-btn')
+        launchBtn.addEventListener('ready', function (e) {
+          console.log('开放标签 ready')
+        })
+        launchBtn.addEventListener('launch', function (e) {
+          console.log('开放标签 success')
+        })
+        launchBtn.addEventListener('error', function (e) {
+          console.log('开放标签 fail', e.detail)
+        })
+
+        wx.config({
+          // debug: true, // 调试时可开启
+          appId: 'wx8533800e393dbd6b', // <!-- replace -->
+          timestamp: 0, // 必填,填任意数字即可
+          nonceStr: 'nonceStr', // 必填,填任意非空字符串即可
+          signature: 'signature', // 必填,填任意非空字符串即可
+          jsApiList: ['chooseImage'], // 必填,随意一个接口即可 
+          openTagList: ['wx-open-launch-weapp'], // 填入打开小程序的开放标签名
+        })
+      } else if (isDesktop) {
+        // 在 pc 上则给提示引导到手机端打开
+        var containerEl = document.getElementById('desktop-web-container')
+        containerEl.classList.remove('hidden')
+        containerEl.classList.add('full', 'desktop-web-container')
+      } else {
+        var containerEl = document.getElementById('public-web-container')
+        containerEl.classList.remove('hidden')
+        containerEl.classList.add('full', 'public-web-container')
+        var c = new cloud.Cloud({
+          // 必填,表示是未登录模式
+          identityless: true,
+          // 资源方 AppID
+          resourceAppid: '小程序 AppID', // <!-- replace -->
+          // 资源方环境 ID
+          resourceEnv: '云开发环境 ID', // <!-- replace -->
+        })
+        await c.init()
+        window.c = c
+
+        var buttonEl = document.getElementById('public-web-jump-button')
+        var buttonLoadingEl = document.getElementById('public-web-jump-button-loading')
+        try {
+          await openWeapp(() => {
+            buttonEl.classList.remove('weui-btn_loading')
+            buttonLoadingEl.classList.add('hidden')
+          })
+        } catch (e) {
+          buttonEl.classList.remove('weui-btn_loading')
+          buttonLoadingEl.classList.add('hidden')
+          throw e
+        }
+      }
+    })
+
+    function ajax(options) {
+      return new Promise((resolve, reject) => {
+        if (!options.url) {
+          alert("确认你的url");
+          return;
+        }
+        let method = options.method || 'GET';
+        let async = options.async || true;
+        let xhr = new XMLHttpRequest();
+        if (method === 'GET') {
+          // url后面添加随机数防止请求缓存
+          xhr.open(method, options.url + "?" + Math.random(), async);
+          xhr.send(null);
+        } else if (method === 'POST') {
+          xhr.open(method, options.url, async);
+          xhr.setRequestHeader('Content-type', 'application/json;charset=utf-8');
+          xhr.send(JSON.stringify(options.data));
+        }
+
+        xhr.onreadystatechange = () => {
+          if (xhr.responseText) {
+            resolve(xhr.responseText);
+          }
+        };
+        xhr.onerror = (e) => {
+          reject(e);
+        }
+      }).catch(e => {
+      });
+    }
+
+    function openWeapp() {
+      ajax({
+        method: 'POST',
+        async: false,
+        url: 'https://test-mp-adm.quanshu123.com/test-api/api/v1/mp/wx/urlschema/generate',
+        data: {
+          path: '/pages/index/index',
+          query: 'id=3847838'
+        }
+      })
+    }
+  </script>
+  <style>
+    .hidden {
+      display: none;
+    }
+
+    .full {
+      position: absolute;
+      top: 0;
+      bottom: 0;
+      left: 0;
+      right: 0;
+    }
+
+    .public-web-container {
+      display: flex;
+      flex-direction: column;
+      align-items: center;
+    }
+
+    .public-web-container p {
+      position: absolute;
+      top: 40%;
+    }
+
+    .public-web-container a {
+      position: absolute;
+      bottom: 40%;
+    }
+
+    .wechat-web-container {
+      display: flex;
+      flex-direction: column;
+      align-items: center;
+    }
+
+    .wechat-web-container p {
+      position: absolute;
+      top: 40%;
+    }
+
+    .wechat-web-container wx-open-launch-weapp {
+      position: absolute;
+      bottom: 40%;
+      left: 0;
+      right: 0;
+      display: flex;
+      flex-direction: column;
+      align-items: center;
+    }
+
+    .desktop-web-container {
+      display: flex;
+      flex-direction: column;
+      align-items: center;
+    }
+
+    .desktop-web-container p {
+      position: absolute;
+      top: 40%;
+    }
+  </style>
+</head>
+
+<body>
+  <div class="page full">
+    <div id="public-web-container" class="hidden">
+      <p class="">正在打开 “盲票小程序”...</p> <!-- replace -->
+      <a id="public-web-jump-button" href="javascript:" class="weui-btn weui-btn_primary weui-btn_loading"
+        onclick="openWeapp()">
+        <span id="public-web-jump-button-loading" class="weui-primary-loading weui-primary-loading_transparent"><i
+            class="weui-primary-loading__dot"></i></span>
+        打开小程序
+      </a>
+    </div>
+    <div id="wechat-web-container" class="hidden">
+      <p class="">点击以下按钮打开 “盲票小程序”</p> <!-- replace -->
+      <!-- 跳转小程序的开放标签。文档 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html -->
+      <wx-open-launch-weapp id="launch-btn" username="gh_cf2872611f66" path="pages/index/index?id=123456"
+        env-version="trial">
+        <!-- replace -->
+        <template>
+          <button
+            style="width: 200px; height: 45px; text-align: center; font-size: 17px; display: block; margin: 0 auto; padding: 8px 24px; border: none; border-radius: 4px; background-color: #07c160; color:#fff;">打开小程序</button>
+        </template>
+      </wx-open-launch-weapp>
+    </div>
+    <div id="desktop-web-container" class="hidden">
+      <p class="">请在手机打开网页链接</p>
+    </div>
+  </div>
+</body>
+
+</html>

+ 7 - 5
src/views/business/coupon/add.vue

@@ -26,7 +26,7 @@
           <!-- <el-form-item label="图片:" prop="picUrl">
             <Upload :value="addData.picUrl ? [{ fileName: addData.picUrl }] : []" @input="addData.picUrl = $event[0] ? $event[0].fileName : ''" :limit="1" />
           </el-form-item> -->
-          <el-form-item v-if="addData.type === 1" label="门店默认承担比例:" prop="channelSharedRate">
+          <el-form-item v-if="addData.type === 2" label="门店默认承担比例:" prop="channelSharedRate">
             <el-input v-model="addData.channelSharedRate" :readonly="readonly" type="number" placeholder="请输入门店默认承担比例">
               <template slot="append">%</template>
             </el-input>
@@ -47,7 +47,7 @@
           <el-form-item label="使用说明:" prop="description">
             <el-input type="textarea" rows="4" :readonly="readonly" v-model="addData.description" placeholder="请输入使用说明 对用户可见"/>
           </el-form-item>
-          <el-form-item v-if="addData.type === 1" label="使用范围:" prop="useArea">进票门店</el-form-item>
+          <el-form-item v-if="addData.type === 2" label="使用范围:" prop="useArea">进票门店</el-form-item>
           <el-form-item v-else label="使用范围:" prop="useArea">
             <el-radio-group v-model="addData.useArea" :disabled="readonly">
               <el-radio :label="0">所有盲票</el-radio>
@@ -150,9 +150,11 @@ export default {
     if (this.id) {
       getCouponDetail(this.id).then(res => {
         const { couponId, title, quantity, discount, channelSharedRate, minOrderAmt, dueDays, description, ticketBoxList } = res.data
-        this.addData = { couponId, title, quantity, discount, channelSharedRate, minOrderAmt, dueDays, description, ticketBoxList }
-        this.addData.type = JSON.parse(res.data.type).value
-        this.addData.useArea = JSON.parse(res.data.useArea).value
+        this.addData = {
+          type: JSON.parse(res.data.type).value,
+          useArea: JSON.parse(res.data.useArea).value,
+          couponId, title, quantity, discount, channelSharedRate, minOrderAmt, dueDays, description, ticketBoxList
+        }
       })
     }
   },

+ 1 - 1
src/views/business/coupon/index.vue

@@ -67,7 +67,7 @@
           <el-button v-if="JSON.parse(row.status).value === 'init'" v-hasPermi="['business:coupon:edit']" type="text" @click="$router.push('/coupon/edit?id=' + row.couponId)">编辑</el-button>
           <el-button v-if="JSON.parse(row.status).value === 'off' || JSON.parse(row.status).value === 'init'" v-hasPermi="['business:coupon:on']" type="text" @click="setStatus(row, 'on')">上架</el-button>
           <el-button v-if="JSON.parse(row.status).value === 'on'" v-hasPermi="['business:coupon:off']" type="text" @click="setStatus(row, 'off')">下架</el-button>
-          <el-button v-if="JSON.parse(row.status).value === 'off'" v-hasPermi="['business:coupon:remove']" class="del" type="text" @click="del(row)">删除</el-button>
+          <el-button v-if="JSON.parse(row.status).value === 'init'" v-hasPermi="['business:coupon:remove']" class="del" type="text" @click="del(row)">删除</el-button>
         </template>
       </el-table-column>
     </el-table>

+ 5 - 6
src/views/business/goods/index.vue

@@ -70,18 +70,17 @@
       <el-table-column label="库存" prop="quantity" />
       <el-table-column label="状态" prop="status">
         <template slot-scope="{row}">
-          <el-tag v-if="row.status === 'on'" type="success">上架</el-tag>
-          <el-tag v-else-if="row.status === 'off'" type="info">下架</el-tag>
+          <el-tag :type="JSON.parse(row.status).value === 'on' ? 'success' : 'info'">{{ JSON.parse(row.status).desc }}</el-tag>
         </template>
       </el-table-column>
       <el-table-column label="排序" prop="sort" />
       <el-table-column fixed="right" align="right" label="操作" width="140">
         <template slot-scope="{row}">
           <!-- <el-button v-hasPermi="['business:goods:query']" type="text">查看</el-button> -->
-          <el-button v-hasPermi="['business:goods:edit']" type="text" @click="$router.push('/goods/edit?id=' + row.goodsId)">编辑</el-button>
-          <el-button v-if="row.status === 'off'" v-hasPermi="['business:goods:on']" type="text" @click="setStatus(row, 'on')">上架</el-button>
-          <el-button v-if="row.status === 'on'" v-hasPermi="['business:goods:off']" type="text" @click="setStatus(row, 'off')">下架</el-button>
-          <el-button v-if="row.status === 'off'" v-hasPermi="['business:coupon:remove']" class="del" type="text" @click="del(row)">删除</el-button>
+          <el-button v-if="JSON.parse(row.status).value === 'init'" v-hasPermi="['business:goods:edit']" type="text" @click="$router.push('/goods/edit?id=' + row.goodsId)">编辑</el-button>
+          <el-button v-if="JSON.parse(row.status).value === 'off' || JSON.parse(row.status).value === 'init'" v-hasPermi="['business:goods:on']" type="text" @click="setStatus(row, 'on')">上架</el-button>
+          <el-button v-if="JSON.parse(row.status).value === 'on'" v-hasPermi="['business:goods:off']" type="text" @click="setStatus(row, 'off')">下架</el-button>
+          <el-button v-if="JSON.parse(row.status).value === 'init'" v-hasPermi="['business:coupon:remove']" class="del" type="text" @click="del(row)">删除</el-button>
         </template>
       </el-table-column>
     </el-table>