소스 검색

open data

Alsmile 1 년 전
부모
커밋
10a1c2bd1c
4개의 변경된 파일102개의 추가작업 그리고 13개의 파일을 삭제
  1. 4 1
      src/http.ts
  2. 4 0
      src/styles/tdesign.css
  3. 2 1
      src/views/components/ChargeCloudPublish.vue
  4. 92 11
      src/views/components/Graphics.vue

+ 4 - 1
src/http.ts

@@ -38,7 +38,10 @@ axios.interceptors.response.use(
       return;
     }
     if (error && error.response) {
-      if (error.response.config.url === '/api/account/profile') {
+      if (
+        error.response.config.url === '/api/account/profile' ||
+        error.response.data.error === '此为付费数据,请购买后访问'
+      ) {
         return;
       }
 

+ 4 - 0
src/styles/tdesign.css

@@ -594,3 +594,7 @@
   min-height: 40px;
   font-size: 14px;
 }
+
+.t-image__wrapper {
+  background: none;
+}

+ 2 - 1
src/views/components/ChargeCloudPublish.vue

@@ -72,6 +72,7 @@ const wechatPayDialog = reactive({
 onBeforeMount(async () => {
   const ret: { list: any } = await axios.post('/api/goods/list', {
     type: '云发布',
+    sort: { createdAt: 1 },
   });
   data.vips = ret.list;
 });
@@ -93,7 +94,7 @@ const onSuccess = (success: boolean) => {
 };
 
 const getPayResult = async () => {
-  const result: { state: number } = await axios.post('/order/pay/state', {
+  const result: { state: number } = await axios.post('/api/order/pay/state', {
     id: data.order.id || data.order._id,
   });
   if (result && result.state) {

+ 92 - 11
src/views/components/Graphics.vue

@@ -178,28 +178,66 @@
     >
       确定删除该数据吗?删除后不可恢复!
     </t-dialog>
+    <t-dialog
+      v-if="chargeDialog.show"
+      :header="chargeDialog.data.name"
+      :visible="true"
+      @close="chargeDialog.show = false"
+      width="70%"
+      :top="8"
+    >
+      <t-image :src="chargeDialog.data.image" />
+      <template #footer>
+        <div class="flex between" style="margin-top: -7px">
+          <p>付费项目,购买后查看并使用</p>
+          <div>
+            <label>金额:</label>
+            <label class="bland">¥{{ chargeDialog.data.price }}</label>
+            <t-button class="primary ml-12" @click="onSubmitOrder"
+              >购买</t-button
+            >
+          </div>
+        </div>
+      </template>
+    </t-dialog>
+
+    <t-dialog
+      v-if="wechatPayDialog.show"
+      v-model:visible="wechatPayDialog.show"
+      class="pay-dialog"
+      header="乐吾乐收银台"
+      :close-on-overlay-click="false"
+      :top="95"
+      :width="700"
+      confirm-btn="支付完成"
+      :cancel-btn="null"
+      @close="getPayResult"
+    >
+      <WechatPay
+        :order="wechatPayDialog.order"
+        :code-url="wechatPayDialog.order.codeUrl"
+        @success="onChargeSuccess"
+      />
+    </t-dialog>
   </div>
 </template>
 
 <script lang="ts" setup>
 import { onMounted, onUnmounted, reactive, ref } from 'vue';
 import { useRouter } from 'vue-router';
+import { MessagePlugin } from 'tdesign-vue-next';
 import axios from 'axios';
 
 import { cases, shapes, formComponents } from '@/services/defaults';
 import { charts } from '@/services/echarts';
 import { getFolders, getFiles, getIcons } from '@/services/png';
-import {
-  getComponents,
-  getComponentsList,
-  getLe5leV,
-  updateCollection,
-} from '@/services/api';
+import { getComponentsList, getLe5leV, updateCollection } from '@/services/api';
 import { convertPen } from '@/services/upgrade';
 import { deepClone } from '@meta2d/core';
 import { isGif } from '@/services/utils';
 import { autoSave, delAttrs } from '@/services/common';
-import { MessagePlugin } from 'tdesign-vue-next';
+
+import WechatPay from './WechatPay.vue';
 
 const router = useRouter();
 
@@ -259,6 +297,10 @@ const pngs = ref([]);
 const icons = ref([]);
 
 let dropped = false;
+const chargeDialog = reactive<any>({});
+const wechatPayDialog = reactive<any>({
+  show: false,
+});
 
 const groupChange = async (name: string) => {
   activedPanel.value = [];
@@ -332,7 +374,7 @@ const getCaseProjects = async (name: string, group?: string) => {
     {
       query,
       shared: 'true',
-      projection: { _id: 1, name: 1, image: 1, price: 1 },
+      projection: { id: 1, _id: 1, name: 1, image: 1, price: 1 },
     }
   );
 
@@ -340,6 +382,9 @@ const getCaseProjects = async (name: string, group?: string) => {
     return [];
   }
   for (const item of ret.list) {
+    if (!item.id) {
+      item.id = item._id;
+    }
     item.draggable = false;
   }
   return ret.list;
@@ -483,6 +528,16 @@ const open = async (item: any) => {
   if (!item || item.draggable !== false) {
     return;
   }
+
+  const ret: any = await getLe5leV(item._id || item.id);
+  if (!ret) {
+    if (item.price > 0) {
+      chargeDialog.data = item;
+      chargeDialog.show = true;
+    }
+    return;
+  }
+
   router.push({
     path: '/',
     query: {
@@ -490,12 +545,12 @@ const open = async (item: any) => {
     },
   });
 
-  const ret: any = await getLe5leV(item._id || item.id);
   for (const k of delAttrs) {
-    delete (ret as any)[k];
+    delete ret[k];
   }
+
+  autoSave();
   meta2d.open(ret);
-  autoSave(true);
 };
 
 const onChangeGroupPanel = async (val: string[]) => {
@@ -825,6 +880,32 @@ const drop = (obj: any) => {
   }
 };
 
+const onSubmitOrder = async () => {
+  const result: any = await axios.post('/api/order/datas/submit', {
+    collection: 'le5leV',
+    id: chargeDialog.data._id,
+  });
+  if (result) {
+    wechatPayDialog.order = result;
+    wechatPayDialog.show = true;
+  }
+};
+
+const getPayResult = async () => {
+  const result: { state: number } = await axios.post('/api/order/pay/state', {
+    id: wechatPayDialog.order.id || wechatPayDialog.order._id,
+  });
+  if (result && result.state) {
+    return true;
+  }
+};
+
+const onChargeSuccess = () => {
+  MessagePlugin.success('支付成功!');
+  wechatPayDialog.show = false;
+  chargeDialog.show = false;
+};
+
 onMounted(() => {
   groupChange('场景');
   document.addEventListener('dragstart', dragstart, false);