zjs_project 3 месяцев назад
Родитель
Сommit
a98b3cbe56
2 измененных файлов с 54 добавлено и 26 удалено
  1. 50 23
      src/utils/feedback.ts
  2. 4 3
      src/views/board/number/index.vue

+ 50 - 23
src/utils/feedback.ts

@@ -8,61 +8,61 @@ import {
 import type { LoadingInstance } from 'element-plus/es/components/loading/src/loading'
 
 export class Feedback {
-    private loadingInstance: LoadingInstance | null = null
-    static instance: Feedback | null = null
+    private loadingInstance : LoadingInstance | null = null
+    static instance : Feedback | null = null
     static getInstance() {
         return this.instance ?? (this.instance = new Feedback())
     }
     // 消息提示
-    msg(msg: string) {
+    msg(msg : string) {
         ElMessage.info(msg)
     }
     // 错误消息
-    msgError(msg: string) {
+    msgError(msg : string) {
         ElMessage.error(msg)
     }
     // 成功消息
-    msgSuccess(msg: string) {
+    msgSuccess(msg : string) {
         ElMessage.success(msg)
     }
     // 警告消息
-    msgWarning(msg: string) {
+    msgWarning(msg : string) {
         ElMessage.warning(msg)
     }
     // 弹出提示
-    alert(msg: string) {
+    alert(msg : string) {
         ElMessageBox.alert(msg, '系统提示')
     }
     // 错误提示
-    alertError(msg: string) {
+    alertError(msg : string) {
         ElMessageBox.alert(msg, '系统提示', { type: 'error' })
     }
     // 成功提示
-    alertSuccess(msg: string) {
+    alertSuccess(msg : string) {
         ElMessageBox.alert(msg, '系统提示', { type: 'success' })
     }
     // 警告提示
-    alertWarning(msg: string) {
+    alertWarning(msg : string) {
         ElMessageBox.alert(msg, '系统提示', { type: 'warning' })
     }
     // 通知提示
-    notify(msg: string) {
+    notify(msg : string) {
         ElNotification.info(msg)
     }
     // 错误通知
-    notifyError(msg: string) {
+    notifyError(msg : string) {
         ElNotification.error(msg)
     }
     // 成功通知
-    notifySuccess(msg: string) {
+    notifySuccess(msg : string) {
         ElNotification.success(msg)
     }
     // 警告通知
-    notifyWarning(msg: string) {
+    notifyWarning(msg : string) {
         ElNotification.warning(msg)
     }
     // 确认窗体
-    confirm(msg: string) {
+    confirm(msg : string) {
         return ElMessageBox.confirm(msg, '温馨提示', {
             confirmButtonText: '确定',
             cancelButtonText: '取消',
@@ -70,7 +70,7 @@ export class Feedback {
         })
     }
     // 提交内容
-    prompt(content: string, title: string, options?: ElMessageBoxOptions) {
+    prompt(content : string, title : string, options ?: ElMessageBoxOptions) {
         return ElMessageBox.prompt(content, title, {
             confirmButtonText: '确定',
             cancelButtonText: '取消',
@@ -78,15 +78,42 @@ export class Feedback {
         })
     }
     // 提交内容
-    messageBox(content: string, title: string) {
-        return ElMessageBox.confirm(content, title="温馨提示",{
-            confirmButtonText: '确定',
-            cancelButtonText: '取消',
-            type: 'warning'
+    messageBox(content : string, imageUrl: string, fileName: string) {
+        ElMessageBox.confirm(
+            content,
+            {
+                title: '温馨提示',
+                dangerouslyUseHTMLString: true, // 允许使用 HTML 字符串
+                confirmButtonText: '下载',
+                cancelButtonText: '取消',
+            }
+        )
+        .then(async () => {
+            const response = await fetch(imageUrl);
+            if (!response.ok) {
+                throw new Error('图片下载失败');
+            }
+            // 将图片数据转换为 Blob
+            const blob = await response.blob();
+            const url = window.URL.createObjectURL(blob);
+            
+            const link = document.createElement('a')
+            link.style.display = 'none'
+            link.href = url
+            link.setAttribute('download', fileName || "img.png")
+            document.body.appendChild(link)
+            link.click()
+            document.body.removeChild(link) // 下载完成移除元素
+            window.URL.revokeObjectURL(url)
+            ElMessage.success('图片下载成功');
+            console.log('用户点击了下载');
         })
+        .catch(() => {
+            console.log('用户点击了取消');
+        });
     }
     // 打开全局loading
-    loading(msg: string) {
+    loading(msg : string) {
         this.loadingInstance = ElLoading.service({
             lock: true,
             text: msg
@@ -100,4 +127,4 @@ export class Feedback {
 
 const feedback = Feedback.getInstance()
 
-export default feedback
+export default feedback

+ 4 - 3
src/views/board/number/index.vue

@@ -75,7 +75,7 @@
                             v-perms="['system:dept:add']"
                             type="primary"
                             link
-                            @click="handleCreate(row.id)"
+                            @click="handleCreate(row.id,row.name)"
                         >
                             生成二维码
                         </el-button>
@@ -155,7 +155,7 @@ const handleAdd = async (id?: number) => {
     editRef.value?.open('add')
 }
 
-const handleCreate = (id?: number) => {
+const handleCreate = (id: number, name: any) => {
     feedback.loading('正在生成...')
     let signParam = {
         brandId: getBrandId(),
@@ -177,7 +177,8 @@ const handleCreate = (id?: number) => {
             feedback.closeLoading()
             let url = res.single?res.single:res;
             console.warn("***url***",url)
-            feedback.prompt("<img src=\"" + url + "\">", {"dangerouslyUseHTMLString": true})
+            let fileName = name + "_minQrcode.png";
+            feedback.messageBox(`<img src="${url}" alt="示例图片"  />`,url, fileName)
         })
     })