Ver código fonte

1、添加代理分享页面

qmj 4 meses atrás
pai
commit
0e1a264e8e

+ 4 - 2
.env.development

@@ -6,8 +6,10 @@ VITE_APP_ENV = 'development'
 
 # 若依管理系统/开发环境
 VITE_APP_BASE_API = '/dev-api'
-//文件路径
-VITE_APP_FILE_PATH=''
+
 //文件路径
 VITE_APP_FILE_PATH='https://api.shoujida.com'
+VITE_APP_FILE_USER_APP_URL='https://loan.waimai-paotui.com'
+
+
 

+ 3 - 1
.env.production

@@ -12,4 +12,6 @@ VITE_BUILD_COMPRESS = gzip
 
 //文件路径
 //VITE_APP_FILE_PATH='https://loanapi.waimai-paotui.com'
-VITE_APP_FILE_PATH='https://api.shoujida.com'
+//VITE_APP_FILE_USER_APP_URL='https://loan.waimai-paotui.com'
+VITE_APP_FILE_PATH='https://api.shoujida.com'
+VITE_APP_FILE_USER_APP_URL='https://shoujida.com'

+ 7 - 0
src/api/menu.js

@@ -23,6 +23,13 @@ export const getRouters = () => {
                         meta: {title: '我的會員', icon: 'user', affix: true},
                         children: []
                     },
+                    {
+                        path: 'agentLink',
+                        component: 'agent/agentLink',
+                        name: 'agentLink',
+                        meta: {title: '代理分享', icon: 'user', affix: true},
+                        children: []
+                    },
                     {
                         path: 'income',
                         component: 'agent/income',

+ 30 - 1
src/layout/components/Navbar.vue

@@ -65,10 +65,15 @@ import RuoYiDoc from '@/components/RuoYi/Doc'
 import useAppStore from '@/store/modules/app'
 import useUserStore from '@/store/modules/user'
 import useSettingsStore from '@/store/modules/settings'
+import usePermissionStore from '@/store/modules/permission'
+import useTagsViewStore from '@/store/modules/tagsView'
+import router from '@/router'
 
 const appStore = useAppStore()
 const userStore = useUserStore()
 const settingsStore = useSettingsStore()
+const permissionStore = usePermissionStore()
+const tagsViewStore = useTagsViewStore()
 
 function toggleSideBar() {
   appStore.toggleSideBar()
@@ -94,7 +99,31 @@ function logout() {
     type: 'warning'
   }).then(() => {
     userStore.logOut().then(() => {
-      location.href = '/index'
+      // 清除权限路由
+      permissionStore.routes = []
+      permissionStore.addRoutes = []
+      // 清除标签页
+      tagsViewStore.visitedViews = []
+      tagsViewStore.cachedViews = []
+      tagsViewStore.iframeViews = []
+      // 跳转到登录页
+      router.push('/login').catch(() => {
+        // 如果路由跳转失败,使用强制跳转
+        window.location.href = '/login'
+      })
+    }).catch(() => {
+      // 即使退出API失败,也清除本地数据并跳转
+      userStore.token = ''
+      userStore.roles = []
+      userStore.permissions = []
+      permissionStore.routes = []
+      permissionStore.addRoutes = []
+      tagsViewStore.visitedViews = []
+      tagsViewStore.cachedViews = []
+      tagsViewStore.iframeViews = []
+      router.push('/login').catch(() => {
+        window.location.href = '/login'
+      })
     })
   }).catch(() => { })
 }

+ 2 - 1
src/utils/request.js

@@ -6,6 +6,7 @@ import { tansParams, blobValidate } from '@/utils/ruoyi'
 import cache from '@/plugins/cache'
 import { saveAs } from 'file-saver'
 import useUserStore from '@/store/modules/user'
+import router from '@/router'
 
 let downloadLoadingInstance
 // 是否显示重新登录
@@ -88,7 +89,7 @@ service.interceptors.response.use(res => {
         ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => {
           isRelogin.show = false
           useUserStore().logOut().then(() => {
-            location.href = '/index'
+            router.push('/login')
           })
       }).catch(() => {
         isRelogin.show = false

+ 210 - 0
src/views/agent/agentLink.vue

@@ -0,0 +1,210 @@
+<template>
+  <div class="app-container">
+    <el-card class="box-card">
+      <template #header>
+        <div class="card-header">
+          <span>代理分享連結</span>
+        </div>
+      </template>
+      <div class="share-link-container">
+        <div class="link-label">您的分享連結:</div>
+        <div class="link-content">
+          <el-input
+            v-model="shareLink"
+            readonly
+            class="link-input"
+          >
+            <template #append>
+              <el-button
+                type="primary"
+                :icon="DocumentCopy"
+                @click="handleCopy"
+              >
+                複製連結
+              </el-button>
+            </template>
+          </el-input>
+        </div>
+        <div class="link-tip">
+          <el-alert
+            title="提示"
+            type="info"
+            :closable="false"
+            show-icon
+          >
+            <template #default>
+              <p>複製此連結發送給其他人,他們可以通過此連結註冊成為您的會員。</p>
+            </template>
+          </el-alert>
+        </div>
+      </div>
+    </el-card>
+  </div>
+</template>
+
+<script setup>
+import { ref, computed, onMounted } from 'vue'
+import { ElMessage } from 'element-plus'
+import { DocumentCopy } from '@element-plus/icons-vue'
+import useUserStore from '@/store/modules/user'
+
+const userStore = useUserStore()
+
+// 分享連結的基礎URL
+const baseUrl =import.meta.env.VITE_APP_FILE_USER_APP_URL+'/#/pages/registerMember'
+
+// 生成分享連結
+const shareLink = computed(() => {
+  if (!userStore.id || !userStore.name) {
+    return ''
+  }
+  
+  // 構建數據對象
+  const data = {
+    agentId: userStore.id,
+    agentName: userStore.name
+  }
+  
+  // 將對象轉換為 JSON 字串,然後進行 base64 編碼
+  const jsonStr = JSON.stringify(data)
+  const base64Data = btoa(unescape(encodeURIComponent(jsonStr)))
+  
+  // 構建完整的分享連結
+  return `${baseUrl}?data=${base64Data}`
+})
+
+// 複製文字到剪貼板
+function copyTextToClipboard(text) {
+  const element = document.createElement('textarea')
+  const previouslyFocusedElement = document.activeElement
+
+  element.value = text
+  element.setAttribute('readonly', '')
+  element.style.contain = 'strict'
+  element.style.position = 'absolute'
+  element.style.left = '-9999px'
+  element.style.fontSize = '12pt'
+
+  const selection = document.getSelection()
+  const originalRange = selection.rangeCount > 0 && selection.getRangeAt(0)
+
+  document.body.append(element)
+  element.select()
+  element.selectionStart = 0
+  element.selectionEnd = text.length
+
+  let isSuccess = false
+  try {
+    isSuccess = document.execCommand('copy')
+  } catch { }
+
+  element.remove()
+
+  if (originalRange) {
+    selection.removeAllRanges()
+    selection.addRange(originalRange)
+  }
+
+  if (previouslyFocusedElement) {
+    previouslyFocusedElement.focus()
+  }
+
+  return isSuccess
+}
+
+// 複製連結
+function handleCopy() {
+  if (!shareLink.value) {
+    ElMessage.warning('分享連結生成失敗,請稍後再試')
+    return
+  }
+  
+  // 優先使用現代 Clipboard API
+  if (navigator.clipboard && window.isSecureContext) {
+    navigator.clipboard.writeText(shareLink.value).then(() => {
+      ElMessage.success('連結已複製到剪貼板,可以貼上發送給其他人了')
+    }).catch(() => {
+      // 如果 Clipboard API 失敗,回退到傳統方法
+      const success = copyTextToClipboard(shareLink.value)
+      if (success) {
+        ElMessage.success('連結已複製到剪貼板,可以貼上發送給其他人了')
+      } else {
+        ElMessage.error('複製失敗,請手動複製連結')
+      }
+    })
+  } else {
+    // 使用傳統方法
+    const success = copyTextToClipboard(shareLink.value)
+    if (success) {
+      ElMessage.success('連結已複製到剪貼板,可以貼上發送給其他人了')
+    } else {
+      ElMessage.error('複製失敗,請手動複製連結')
+    }
+  }
+}
+
+onMounted(() => {
+  // 確保用戶資訊已載入
+  if (!userStore.name && userStore.token) {
+    userStore.getInfo().catch(() => {
+      ElMessage.error('獲取用戶資訊失敗')
+    })
+  }
+})
+</script>
+
+<style scoped lang="scss">
+.app-container {
+  padding: 20px;
+}
+
+.box-card {
+  max-width: 900px;
+  margin: 0 auto;
+}
+
+.card-header {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  font-size: 18px;
+  font-weight: 600;
+  color: #303133;
+}
+
+.share-link-container {
+  padding: 20px 0;
+}
+
+.link-label {
+  font-size: 14px;
+  color: #606266;
+  margin-bottom: 12px;
+  font-weight: 500;
+}
+
+.link-content {
+  margin-bottom: 20px;
+  
+  .link-input {
+    :deep(.el-input__inner) {
+      font-size: 14px;
+      color: #303133;
+    }
+  }
+}
+
+.link-tip {
+  margin-top: 20px;
+  
+  :deep(.el-alert) {
+    .el-alert__content {
+      p {
+        margin: 0;
+        line-height: 1.6;
+        color: #606266;
+      }
+    }
+  }
+}
+</style>

+ 41 - 41
src/views/agent/myuser.vue

@@ -61,47 +61,47 @@
       </el-form-item>
     </el-form>
 
-    <el-row :gutter="10" class="mb8">
-      <el-col :span="1.5">
-        <el-button
-            type="primary"
-            plain
-            icon="Plus"
-            @click="handleAdd"
-            v-hasPermi="['system:loanuser:add']"
-        >新增</el-button>
-      </el-col>
-      <el-col :span="1.5">
-        <el-button
-            type="success"
-            plain
-            icon="Edit"
-            :disabled="single"
-            @click="handleUpdate"
-            v-hasPermi="['system:loanuser:edit']"
-        >修改</el-button>
-      </el-col>
-      <el-col :span="1.5">
-        <el-button
-            type="danger"
-            plain
-            icon="Delete"
-            :disabled="multiple"
-            @click="handleDelete"
-            v-hasPermi="['system:loanuser:remove']"
-        >刪除</el-button>
-      </el-col>
-      <el-col :span="1.5">
-        <el-button
-            type="warning"
-            plain
-            icon="Download"
-            @click="handleExport"
-            v-hasPermi="['system:loanuser:export']"
-        >匯出</el-button>
-      </el-col>
-      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
-    </el-row>
+<!--    <el-row :gutter="10" class="mb8">-->
+<!--      <el-col :span="1.5">-->
+<!--        <el-button-->
+<!--            type="primary"-->
+<!--            plain-->
+<!--            icon="Plus"-->
+<!--            @click="handleAdd"-->
+<!--            v-hasPermi="['system:loanuser:add']"-->
+<!--        >新增</el-button>-->
+<!--      </el-col>-->
+<!--      <el-col :span="1.5">-->
+<!--        <el-button-->
+<!--            type="success"-->
+<!--            plain-->
+<!--            icon="Edit"-->
+<!--            :disabled="single"-->
+<!--            @click="handleUpdate"-->
+<!--            v-hasPermi="['system:loanuser:edit']"-->
+<!--        >修改</el-button>-->
+<!--      </el-col>-->
+<!--      <el-col :span="1.5">-->
+<!--        <el-button-->
+<!--            type="danger"-->
+<!--            plain-->
+<!--            icon="Delete"-->
+<!--            :disabled="multiple"-->
+<!--            @click="handleDelete"-->
+<!--            v-hasPermi="['system:loanuser:remove']"-->
+<!--        >刪除</el-button>-->
+<!--      </el-col>-->
+<!--      <el-col :span="1.5">-->
+<!--        <el-button-->
+<!--            type="warning"-->
+<!--            plain-->
+<!--            icon="Download"-->
+<!--            @click="handleExport"-->
+<!--            v-hasPermi="['system:loanuser:export']"-->
+<!--        >匯出</el-button>-->
+<!--      </el-col>-->
+<!--      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>-->
+<!--    </el-row>-->
 
     <el-table v-loading="loading" :data="loanuserList" @selection-change="handleSelectionChange">
       <el-table-column type="selection" width="50" align="center" />

+ 1 - 1
src/views/error/404.vue

@@ -17,7 +17,7 @@
         <div class="bullshit__info">
           对不起,您正在寻找的页面不存在。尝试检查URL的错误,然后按浏览器上的刷新按钮或尝试在我们的应用程序中找到其他内容。
         </div>
-        <router-link to="/index" class="bullshit__return-home">
+        <router-link to="/user/myuser" class="bullshit__return-home">
           返回首页
         </router-link>
       </div>

+ 16 - 3
vite.config.js

@@ -3,8 +3,8 @@ import path from 'path'
 import createVitePlugins from './vite/plugins'
 
 // const baseUrl = 'http://localhost:8080' // 后端接口
-// const baseUrl = 'https://loanagent.waimai-paotui.com' // 后端接口
-const baseUrl="https://agent.shoujida.com"
+// const baseUrl = 'https://loanapi.waimai-paotui.com' // 后端接口
+const baseUrl="https://api.shoujida.com"
 
 // https://vitejs.dev/config/
 export default defineConfig(({ mode, command }) => {
@@ -52,12 +52,25 @@ export default defineConfig(({ mode, command }) => {
         '/dev-api': {
           target: baseUrl,
           changeOrigin: true,
-          rewrite: (p) => p.replace(/^\/dev-api/, '')
+          secure: false, // 如果是 https 接口,需要配置这个参数
+          rewrite: (p) => p.replace(/^\/dev-api/, ''),
+          configure: (proxy, options) => {
+            proxy.on('error', (err, req, res) => {
+              console.log('proxy error', err);
+            });
+            proxy.on('proxyReq', (proxyReq, req, res) => {
+              console.log('Sending Request to the Target:', req.method, req.url);
+            });
+            proxy.on('proxyRes', (proxyRes, req, res) => {
+              console.log('Received Response from the Target:', proxyRes.statusCode, req.url);
+            });
+          }
         },
          // springdoc proxy
          '^/v3/api-docs/(.*)': {
           target: baseUrl,
           changeOrigin: true,
+          secure: false,
         }
       }
     },