Ver código fonte

数据报表预览分享

zhengjinyi 1 ano atrás
pai
commit
aa6cb4bda6

+ 114 - 0
src/views/user/customer/components/share-dialog.vue

@@ -0,0 +1,114 @@
+<template>
+  <el-dialog title="预览" :visible.sync="visible" width="550px" :close-on-click-modal="false" :show-close="false">
+    <p style="line-height: 24px; margin-bottom: 10px">
+      预览码:
+      <span style="color: red">{{ shareCode }}(24小时内有效)</span>
+    </p>
+    <p style="line-height: 24px; margin-bottom: 10px">
+      预览链接:
+      <span style="color: #999999">{{ shareLink }}</span>
+    </p>
+    <p style="line-height: 24px; margin-bottom: 10px">
+      <el-tag type="info">查看预览链接需要输入预览码,预览码24小时内有效,失效后需要重新进行预览操作获取。</el-tag>
+    </p>
+    <div slot="footer">
+      <el-button type="primary" @click="handleConfirm"> 直接预览 </el-button>
+      <el-button type="primary" @click="handleCopy"> 全部复制 </el-button>
+      <el-button @click="handleCanle"> 取 消 </el-button>
+    </div>
+  </el-dialog>
+</template>
+
+<script>
+import { getCustomerShopList } from '@/api/user/customer/customer'
+
+export default {
+  name: 'ShareDialog',
+  filters: {
+    NumFormat(value) {
+      // 处理金额
+      return Number(value).toFixed(2)
+    }
+  },
+  props: {
+    shareInfo: {
+      type: Object,
+      default: null
+    },
+    shareCode: {
+      type: Number,
+      default: 2345
+    },
+    shareLink: {
+      type: String,
+      default: ''
+    },
+    productName: {
+      type: String,
+      default: ''
+    }
+  },
+  data() {
+    return {
+      visible: true
+    }
+  },
+  computed: {},
+  created() {},
+  methods: {
+    // 获取所有供应商列表
+    async getCustomerShopList() {
+      try {
+        const res = await getCustomerShopList(this.listQuery)
+        this.list = res.data.results
+        this.total = res.data.totalRecord
+        this.isLoading = false
+      } catch (error) {
+        console.log(error)
+      }
+    },
+    // 全部复制链接
+    handleCopy() {
+      const truncatedName = this.truncateStringWithEllipsis(this.productName, 18)
+      const clipboardText = `商品${truncatedName}\n【${this.shareInfo.reportDate}】数据报表\n预览链接:${this.shareLink}\n预览码:${this.shareCode}(24小时内有效)`
+      navigator.clipboard
+        .writeText(clipboardText)
+        .then(() => {
+          this.$notify({
+            title: '复制成功!',
+            message: '',
+            type: 'success'
+          })
+        })
+        .catch((err) => {
+          console.error('复制失败:', err)
+        })
+    },
+
+    // 直接预览
+    handleConfirm() {
+      window.open(this.shareLink, '_blank')
+    },
+    handleCanle() {
+      // 取消弹窗
+      this.$emit('cancel')
+    },
+    truncateStringWithEllipsis(str, maxLength) {
+      if (str.length <= maxLength) {
+        return str // 如果字符串长度小于或等于最大长度,直接返回原字符串
+      } else {
+        const startIndex = maxLength - 3 // 从第10个字符开始
+        const endIndex = str.length - 3 // 保留最后3个字符
+        return `${str.slice(0, startIndex)}...${str.slice(endIndex)}` // 在中间插入省略号并返回截取后的字符串
+      }
+    }
+  }
+}
+</script>
+<style lang="scss" scoped>
+::v-deep {
+  thead .el-checkbox {
+    display: none !important;
+  }
+}
+</style>

+ 1 - 1
src/views/user/customer/list.vue

@@ -95,7 +95,7 @@
 import { getCustomerShopList, saveCustomerShop, renewCustomerShop } from '@/api/user/customer/customer'
 import ShopDialog from './components/shop-dialog'
 export default {
-  name: 'RecordList',
+  name: 'CustomerList',
   components: { ShopDialog },
   filters: {},
   data() {

+ 26 - 3
src/views/user/customer/market-report-list.vue

@@ -63,14 +63,26 @@
       :limit.sync="listQuery.pageSize"
       @pagination="getMarketReportList"
     />
+    <!--  预览弹窗 -->
+    <share-dialog
+      v-if="dialogVisible"
+      ref="shopDialog"
+      :product-name="productName"
+      :share-code="shareCode"
+      :share-link="shareLink"
+      :share-info="shareInfo"
+      @cancel="handleCancel"
+    />
   </div>
 </template>
 
 <script>
 import { getMarketReportList, updateVisible, deleteMarketReport } from '@/api/user/customer/customer'
+import ShareDialog from './components/share-dialog'
 import { downloadWithUrl } from '@/utils'
 export default {
   name: 'CustomerStatList',
+  components: { ShareDialog },
   filters: {},
   data() {
     return {
@@ -84,7 +96,11 @@ export default {
         pageSize: 100
       },
       list: [],
-      total: 0
+      total: 0,
+      shareCode: 0,
+      shareLink: '',
+      shareInfo: {},
+      dialogVisible: false
     }
   },
   computed: {},
@@ -154,8 +170,15 @@ export default {
     },
     // 跳转预览
     handlePreview(row) {
-      const urls = `${process.env.VUE_APP_CAIMEI_URL}/supplier/charts.html?type=1&shopId=${row.shopId}&marketReportId=${row.id}`
-      window.open(urls, '_blank')
+      const urls = `${process.env.VUE_APP_CAIMEI_URL}/charts-preview.html?type=1&shopId=${row.shopId}&marketReportId=${row.id}`
+      this.shareCode = 4567
+      this.shareLink = urls
+      this.shareInfo = row
+      this.dialogVisible = true
+    },
+    // 取消预览
+    handleCancel() {
+      this.dialogVisible = false
     },
     // 添加/编辑
     handleUpdate(type, row) {