Browse Source

添加平台标识

HuRongxin 6 days ago
parent
commit
3bbbf085c6
3 changed files with 164 additions and 0 deletions
  1. 52 0
      src/utils/platform.ts
  2. 8 0
      src/utils/request.ts
  3. 104 0
      src/views/system/tenant/index.vue

+ 52 - 0
src/utils/platform.ts

@@ -0,0 +1,52 @@
+// src/utils/platform.ts
+const SUPPORTED_PLATFORMS = ['main', 'oms', 'crm', 'pms', 'yuncai'] as const;
+type PlatformCode = (typeof SUPPORTED_PLATFORMS)[number];
+
+/**
+ * 从当前域名自动解析 platform_code
+ * 支持:
+ *   - oms.yoe365.com       → oms
+ *   - crm.yoe365.com:8080  → crm
+ *   - localhost            → oms (开发默认)
+ *   - 127.0.0.1            → oms
+ *   - yuncai.dev.local     → yuncai
+ */
+export function getPlatformCode(): PlatformCode {
+  let host = window.location.host;
+
+  // 移除端口(如 :8080)
+  if (host.includes(':')) {
+    host = host.split(':')[0];
+  }
+
+  // 开发环境特殊映射
+  const devMap: Record<string, PlatformCode> = {
+    'localhost': 'oms',
+    '127.0.0.1': 'oms',
+    'oms.dev.local': 'oms',
+    'crm.dev.local': 'crm',
+    'yuncai.dev.local': 'yuncai',
+    'pms.dev.local': 'pms'
+  };
+
+  if (devMap[host]) {
+    return devMap[host];
+  }
+
+  // 生产环境:泛解析 *.yoe365.com
+  const PROD_DOMAIN_SUFFIX = '.yoe365.com';
+  if (host.endsWith(PROD_DOMAIN_SUFFIX)) {
+    const subdomain = host.slice(0, -PROD_DOMAIN_SUFFIX.length);
+    if (SUPPORTED_PLATFORMS.includes(subdomain as PlatformCode)) {
+      return subdomain as PlatformCode;
+    }
+  }
+
+  // IP 地址或未知域名 → 默认 oms(开发友好)
+  if (/^\d+\.\d+\.\d+\.\d+$/.test(host)) {
+    return 'oms';
+  }
+
+  // 最终 fallback
+  return 'main';
+}

+ 8 - 0
src/utils/request.ts

@@ -10,6 +10,7 @@ import FileSaver from 'file-saver';
 import { getLanguage } from '@/lang';
 import { encryptBase64, encryptWithAes, generateAesKey, decryptWithAes, decryptBase64 } from '@/utils/crypto';
 import { encrypt, decrypt } from '@/utils/jsencrypt';
+import { getPlatformCode } from '@/utils/platform';
 import router from '@/router';
 
 const encryptHeader = 'encrypt-key';
@@ -34,6 +35,12 @@ const service = axios.create({
 // 请求拦截器
 service.interceptors.request.use(
   (config: InternalAxiosRequestConfig) => {
+    // >>> 新增:平台标识 <<<
+    const platformCode = getPlatformCode();
+    if (platformCode) {
+      config.headers['X-Platform-Code'] = platformCode;
+    }
+
     // 对应国际化资源文件后缀
     config.headers['Content-Language'] = getLanguage();
 
@@ -46,6 +53,7 @@ service.interceptors.request.use(
     if (getToken() && !isToken) {
       config.headers['Authorization'] = 'Bearer ' + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
     }
+
     // get请求映射params参数
     if (config.method === 'get' && config.params) {
       let url = config.url + '?' + tansParams(config.params);

+ 104 - 0
src/views/system/tenant/index.vue

@@ -135,6 +135,58 @@
         <el-form-item label="备注" prop="remark">
           <el-input v-model="form.remark" placeholder="请输入备注" />
         </el-form-item>
+        <!-- <el-form-item label="Logo" prop="logo">
+          <div style="display: flex; align-items: center; gap: 12px">
+             当前Logo预览或上传区域 
+            <div v-if="form.logo" style="flex-shrink: 0">
+              <el-image
+                :src="form.logo"
+                :preview-disabled="true"
+                fit="cover"
+                style="width: 200px; height: 200px; border-radius: 4px; border: 1px solid #dcdfe6"
+              />
+            </div>
+            <div
+              v-else
+              @click="openLogoSelector"
+              style="
+                width: 200px;
+                height: 200px;
+                border: 1px dashed #dcdfe6;
+                border-radius: 4px;
+                display: flex;
+                align-items: center;
+                justify-content: center;
+                color: #999;
+                font-size: 12px;
+                cursor: pointer;
+                transition: all 0.3s;
+              "
+              class="logo-upload-area"
+            >
+              点击上传
+            </div>
+
+            建议尺寸和清除按钮 
+            <div style="flex: 1">
+              <div style="color: #909399; font-size: 12px; line-height: 1.4">
+                建议尺寸:200×200px<br />
+                支持 JPG/PNG 格式
+              </div>
+              <el-button v-if="form.logo" @click="clearLogo" size="small" style="margin-top: 8px">清除</el-button>
+            </div>
+          </div>
+
+           Logo选择器对话框 
+          <FileSelector
+            v-model="logoSelectorVisible"
+            title="选择品牌Logo"
+            :allowed-types="[1]"
+            :multiple="false"
+            :allow-upload="true"
+            @confirm="handleLogoSelected"
+          />
+        </el-form-item> -->
       </el-form>
       <template #footer>
         <div class="dialog-footer">
@@ -158,6 +210,7 @@ import {
   syncTenantDict,
   syncTenantConfig
 } from '@/api/system/tenant';
+import FileSelector from '@/components/FileSelector/index.vue';
 import { selectTenantPackage } from '@/api/system/tenantPackage';
 import { useUserStore } from '@/store/modules/user';
 import { TenantForm, TenantQuery, TenantVO } from '@/api/system/tenant/types';
@@ -232,6 +285,20 @@ const data = reactive<PageData<TenantForm, TenantQuery>>({
 
 const { queryParams, form, rules } = toRefs(data);
 
+// Logo选择器相关
+const logoSelectorVisible = ref(false);
+
+// 监听对话框关闭,清理表单验证状态
+watch(logoSelectorVisible, (newVal) => {
+  if (!newVal) {
+    // 对话框关闭后清理可能的表单验证状态
+    nextTick(() => {
+      queryFormRef.value?.clearValidate();
+      tenantFormRef.value?.clearValidate();
+    });
+  }
+});
+
 /** 查询所有租户套餐 */
 const getTenantPackage = async () => {
   const res = await selectTenantPackage();
@@ -247,6 +314,43 @@ const getList = async () => {
   loading.value = false;
 };
 
+// 打开Logo选择器
+const openLogoSelector = () => {
+  // 在打开前清理表单验证状态
+  nextTick(() => {
+    queryFormRef.value?.clearValidate();
+    tenantFormRef.value?.clearValidate();
+  });
+  logoSelectorVisible.value = true;
+};
+
+// 清除Logo
+const clearLogo = () => {
+  //   form.value.logo = '';
+  ElMessage.success('Logo已清除');
+};
+
+// Logo选择处理
+const handleLogoSelected = (files: any[]) => {
+  if (files && files.length > 0) {
+    const file = files[0]; // 取第一个文件
+    if (file && (file.url || file.path)) {
+      //   form.value.logo = file.url || file.path;
+      ElMessage.success('Logo选择成功');
+
+      // 选择完成后清理表单验证状态
+      nextTick(() => {
+        queryFormRef.value?.clearValidate();
+        tenantFormRef.value?.clearValidate();
+      });
+    } else {
+      ElMessage.error('请选择有效的图片文件');
+    }
+  } else {
+    ElMessage.error('请选择有效的图片文件');
+  }
+};
+
 // 租户套餐状态修改
 const handleStatusChange = async (row: TenantVO) => {
   const text = row.status === '0' ? '启用' : '停用';