liuxiaole 2 недель назад
Родитель
Сommit
1383f26294
3 измененных файлов с 58 добавлено и 271 удалено
  1. 1 2
      .env.development
  2. 13 32
      src/api/modules/newLoginApi.ts
  3. 44 237
      src/views/storeDecoration/receivingAccount/index.vue

+ 1 - 2
.env.development

@@ -24,8 +24,7 @@ VITE_API_URL_PLATFORM = /api/alienStorePlatform
 
 # 开发环境跨域代理,支持配置多个
 # VITE_PROXY = [["/api","https://api.ailien.shop"]] #生产环境
-# VITE_PROXY = [["/api","http://120.26.186.130:8000"]] # 邹建宇
-VITE_PROXY = [["/api","http://192.168.10.80:8000"]] # 邹建宇
+VITE_PROXY = [["/api","http://120.26.186.130:8000"]] # 邹建宇
 
 
 # WebSocket 基础地址(分享等能力,与商家端一致)

+ 13 - 32
src/api/modules/newLoginApi.ts

@@ -342,7 +342,7 @@ export const deleteDynamicsById = (params: any) => {
 };
 
 /** 数据字典(如银行名称 type: bankName) */
-export const getDict = (params: { type: string }) => {
+export const getDict = (params: { dictType: string }) => {
   return httpLogin.get(`/alienStore/dict/getDict`, params);
 };
 
@@ -352,45 +352,26 @@ export const getPaymentStoreUserId = (params: any) => {
 };
 
 /**
- * 以 multipart/form-data 方式保存微信支付配置(公钥、私钥以文件上传,Web 端传 File)
- * @param formFields - 除证书外的表单字段(storeUserId、apiV3Key、wechatAppId 等)
- * @param privateKeyFile - 私钥证书文件(input type="file" 的 file)
- * @param publicKeyFile - 公钥证书文件
+ * 保存微信收款配置(multipart/form-data,仅三字段)
+ * storeUserId:店铺用户ID;storeWechatId:商家微信 appid;storeWechatName:商家微信名称
  */
-export const saveWechatWithFiles = (
-  formFields: Record<string, string>,
-  privateKeyFile?: File | null,
-  publicKeyFile?: File | null
-) => {
+export const saveWechatWithFiles = (params: { storeUserId: string | number; storeWechatId: string; storeWechatName: string }) => {
   const fd = new FormData();
-  Object.entries(formFields).forEach(([key, value]) => {
-    if (value != null && value !== "") fd.append(key, String(value));
-  });
-  if (privateKeyFile) fd.append("wechatPrivateKeyFile", privateKeyFile);
-  if (publicKeyFile) fd.append("wechatPayPublicKeyFile", publicKeyFile);
+  fd.append("storeUserId", String(params.storeUserId));
+  fd.append("storeWechatId", params.storeWechatId.trim());
+  fd.append("storeWechatName", params.storeWechatName.trim());
   return httpLogin.post(`/alienStore/store/payment/config/saveWechatByStoreUserId`, fd);
 };
 
 /**
- * 以 multipart/form-data 方式保存支付宝支付配置(应用公钥、支付宝公钥、根证书以文件上传,Web 端传 File)
- * @param formFields - 除证书外的表单字段(storeUserId、appId、appSecretCert 等)
- * @param appPublicCertFile - 应用公钥证书文件
- * @param alipayPublicCertFile - 支付宝公钥证书文件
- * @param alipayRootCertFile - 支付宝根证书文件
+ * 保存支付宝收款配置(multipart/form-data,仅三字段)
+ * storeUserId:店铺用户ID;storeAliId:商家支付宝 appId;storeAliName:商家支付宝名称
  */
-export const saveAlipayWithFiles = (
-  formFields: Record<string, string>,
-  appPublicCertFile?: File | null,
-  alipayPublicCertFile?: File | null,
-  alipayRootCertFile?: File | null
-) => {
+export const saveAlipayWithFiles = (params: { storeUserId: string | number; storeAliId: string; storeAliName: string }) => {
   const fd = new FormData();
-  Object.entries(formFields).forEach(([key, value]) => {
-    if (value != null && value !== "") fd.append(key, String(value));
-  });
-  if (appPublicCertFile) fd.append("appPublicCert", appPublicCertFile);
-  if (alipayPublicCertFile) fd.append("alipayPublicCert", alipayPublicCertFile);
-  if (alipayRootCertFile) fd.append("alipayRootCert", alipayRootCertFile);
+  fd.append("storeUserId", String(params.storeUserId));
+  fd.append("storeAliId", params.storeAliId.trim());
+  fd.append("storeAliName", params.storeAliName.trim());
   return httpLogin.post(`/alienStore/store/payment/config/saveAlipayByStoreUserId`, fd);
 };
 

+ 44 - 237
src/views/storeDecoration/receivingAccount/index.vue

@@ -2,7 +2,7 @@
   <div class="receiving-account-page">
     <h2 class="page-title">收款账号</h2>
     <p class="page-tip">
-      请选择收款方式并填写相关信息;配置微信/支付宝商户参数或绑定借记卡银行账户,带 * 为必填项。修改后请保存。
+      请选择收款方式并填写商户信息;微信/支付宝各填写商户ID与商户ID号码,或绑定借记卡银行账户,带 * 为必填项。修改后请保存。
     </p>
 
     <el-card shadow="never" class="form-card">
@@ -16,121 +16,20 @@
         </el-form-item>
 
         <template v-if="form.accountType === 'wechat'">
-          <el-form-item label="appid" prop="wechatAppid">
-            <el-input v-model="form.wechatAppid" placeholder="请输入" clearable />
+          <el-form-item label="商户ID" prop="wechatAppid">
+            <el-input v-model="form.wechatAppid" placeholder="请输入商户ID" clearable />
           </el-form-item>
-          <el-form-item label="mchld" prop="wechatMchld">
-            <el-input v-model="form.wechatMchld" placeholder="请输入" clearable />
-          </el-form-item>
-          <el-form-item label="API证书序列号" prop="wechatApiCertSerialNo">
-            <el-input v-model="form.wechatApiCertSerialNo" placeholder="请输入" clearable />
-          </el-form-item>
-          <el-form-item label="APIv3 Key" prop="wechatApiV3Key">
-            <el-input v-model="form.wechatApiV3Key" placeholder="请输入" clearable />
-          </el-form-item>
-          <el-form-item label="支付公钥ID" prop="wechatPayPublicKeyId">
-            <el-input v-model="form.wechatPayPublicKeyId" placeholder="请输入" clearable />
-          </el-form-item>
-          <el-form-item label="私钥证书" prop="wechatPrivateKeyFile">
-            <el-upload
-              v-model:file-list="form.wechatPrivateKeyFile"
-              class="cert-upload"
-              drag
-              :auto-upload="false"
-              :limit="1"
-              accept=".pem"
-              :on-exceed="() => ElMessage.warning('最多上传1个文件')"
-            >
-              <div class="upload-inner">
-                <el-icon :size="32" color="#6c8ff8">
-                  <UploadFilled />
-                </el-icon>
-                <p>点击或拖拽 .pem 至此处</p>
-                <span>不超过 2MB</span>
-              </div>
-            </el-upload>
-          </el-form-item>
-          <el-form-item label="公钥证书" prop="wechatPayPublicKeyFile">
-            <el-upload
-              v-model:file-list="form.wechatPayPublicKeyFile"
-              class="cert-upload"
-              drag
-              :auto-upload="false"
-              :limit="1"
-              accept=".pem"
-              :on-exceed="() => ElMessage.warning('最多上传1个文件')"
-            >
-              <div class="upload-inner">
-                <el-icon :size="32" color="#6c8ff8">
-                  <UploadFilled />
-                </el-icon>
-                <p>点击或拖拽 .pem 至此处</p>
-                <span>不超过 2MB</span>
-              </div>
-            </el-upload>
+          <el-form-item label="商户ID号码" prop="wechatMchld">
+            <el-input v-model="form.wechatMchld" placeholder="请输入商户ID号码" clearable />
           </el-form-item>
         </template>
 
         <template v-else-if="form.accountType === 'alipay'">
-          <el-form-item label="应用ID" prop="aliAppid">
-            <el-input v-model="form.aliAppid" placeholder="请输入" clearable />
+          <el-form-item label="商户ID" prop="aliAppid">
+            <el-input v-model="form.aliAppid" placeholder="请输入商户ID" clearable />
           </el-form-item>
-          <el-form-item label="应用私钥" prop="aliPrivateId">
-            <el-input v-model="form.aliPrivateId" type="textarea" :rows="4" placeholder="请输入应用私钥" />
-          </el-form-item>
-          <el-form-item label="应用公钥证书" prop="appPublicCertFile">
-            <el-upload
-              v-model:file-list="form.appPublicCertFile"
-              class="cert-upload"
-              drag
-              :auto-upload="false"
-              :limit="1"
-              accept=".crt,.pem"
-              :on-exceed="() => ElMessage.warning('最多上传1个文件')"
-            >
-              <div class="upload-inner">
-                <el-icon :size="32" color="#6c8ff8">
-                  <UploadFilled />
-                </el-icon>
-                <p>应用公钥证书</p>
-              </div>
-            </el-upload>
-          </el-form-item>
-          <el-form-item label="支付宝公钥证书" prop="alipayPublicCertFile">
-            <el-upload
-              v-model:file-list="form.alipayPublicCertFile"
-              class="cert-upload"
-              drag
-              :auto-upload="false"
-              :limit="1"
-              accept=".crt,.pem"
-              :on-exceed="() => ElMessage.warning('最多上传1个文件')"
-            >
-              <div class="upload-inner">
-                <el-icon :size="32" color="#6c8ff8">
-                  <UploadFilled />
-                </el-icon>
-                <p>支付宝公钥证书</p>
-              </div>
-            </el-upload>
-          </el-form-item>
-          <el-form-item label="支付宝根证书" prop="alipayRootCertFile">
-            <el-upload
-              v-model:file-list="form.alipayRootCertFile"
-              class="cert-upload"
-              drag
-              :auto-upload="false"
-              :limit="1"
-              accept=".crt,.pem"
-              :on-exceed="() => ElMessage.warning('最多上传1个文件')"
-            >
-              <div class="upload-inner">
-                <el-icon :size="32" color="#6c8ff8">
-                  <UploadFilled />
-                </el-icon>
-                <p>支付宝根证书</p>
-              </div>
-            </el-upload>
+          <el-form-item label="商户ID号码" prop="aliPrivateId">
+            <el-input v-model="form.aliPrivateId" placeholder="请输入商户ID号码" clearable />
           </el-form-item>
         </template>
 
@@ -159,8 +58,7 @@
 <script setup lang="ts">
 import { ref, reactive, onMounted, computed, watch } from "vue";
 import { ElMessage } from "element-plus";
-import type { FormInstance, FormRules, UploadUserFile } from "element-plus";
-import { UploadFilled } from "@element-plus/icons-vue";
+import type { FormInstance, FormRules } from "element-plus";
 import {
   getDict,
   getPaymentStoreUserId,
@@ -205,35 +103,22 @@ const form = reactive({
   accountType: "wechat",
   wechatAppid: "",
   wechatMchld: "",
-  wechatApiCertSerialNo: "",
-  wechatApiV3Key: "",
-  wechatPayPublicKeyId: "" as string | null,
-  wechatPrivateKeyFile: [] as UploadUserFile[],
-  wechatPayPublicKeyFile: [] as UploadUserFile[],
   aliAppid: "",
   aliPrivateId: "",
-  alipayRootCertFile: [] as UploadUserFile[],
-  alipayPublicCertFile: [] as UploadUserFile[],
-  appPublicCertFile: [] as UploadUserFile[],
   bankName: "",
   bankAccountNo: ""
 });
 
 const wechatRules: FormRules = {
   accountType: [{ required: true, message: "请选择账号类型", trigger: "change" }],
-  wechatAppid: [{ required: true, message: "请输入appid", trigger: "blur" }],
-  wechatMchld: [{ required: true, message: "请输入mchId", trigger: "blur" }],
-  wechatApiCertSerialNo: [{ required: true, message: "请输入API证书序列号", trigger: "blur" }],
-  wechatApiV3Key: [{ required: true, message: "请输入APIv3 Key", trigger: "blur" }],
-  wechatPayPublicKeyId: [{ required: true, message: "请输入支付公钥ID", trigger: "blur" }],
-  wechatPrivateKeyFile: [{ required: true, type: "array", min: 1, message: "请上传私钥证书", trigger: "change" }],
-  wechatPayPublicKeyFile: [{ required: true, type: "array", min: 1, message: "请上传公钥证书", trigger: "change" }]
+  wechatAppid: [{ required: true, message: "请输入商户ID", trigger: "blur" }],
+  wechatMchld: [{ required: true, message: "请输入商户ID号码", trigger: "blur" }]
 };
 
 const alipayRules: FormRules = {
   accountType: [{ required: true, message: "请选择账号类型", trigger: "change" }],
-  aliAppid: [{ required: true, message: "请输入应用ID", trigger: "blur" }],
-  aliPrivateId: [{ required: true, message: "请输入应用私钥", trigger: "blur" }]
+  aliAppid: [{ required: true, message: "请输入商户ID", trigger: "blur" }],
+  aliPrivateId: [{ required: true, message: "请输入商户ID号码", trigger: "blur" }]
 };
 
 const bankRules: FormRules = {
@@ -268,13 +153,7 @@ watch(
   }
 );
 
-const base64ToFile = (base64Str: string, fileName: string): File => {
-  const bstr = atob(base64Str);
-  const u8arr = new Uint8Array(bstr.length);
-  for (let i = 0; i < bstr.length; i++) u8arr[i] = bstr.charCodeAt(i);
-  return new File([u8arr], fileName, { type: "application/x-pem-file" });
-};
-
+/** 从接口拉取收款配置,用于页面进入时初始化表单,以及「取消」时放弃本地修改并重新回填 */
 const fetchPayAccountConfig = async () => {
   const storeUserId = localGet("geeker-user")?.userInfo?.id;
   if (!storeUserId) {
@@ -289,61 +168,36 @@ const fetchPayAccountConfig = async () => {
 
   form.wechatAppid = "";
   form.wechatMchld = "";
-  form.wechatApiCertSerialNo = "";
-  form.wechatApiV3Key = "";
-  form.wechatPayPublicKeyId = null;
-  form.wechatPrivateKeyFile = [];
-  form.wechatPayPublicKeyFile = [];
   form.aliAppid = "";
   form.aliPrivateId = "";
-  form.appPublicCertFile = [];
-  form.alipayPublicCertFile = [];
-  form.alipayRootCertFile = [];
   form.bankName = "";
   form.bankAccountNo = "";
 
-  if (data.wechatAppId) {
-    form.accountType = "wechat";
-    form.wechatAppid = data.wechatAppId ?? "";
-    form.wechatMchld = data.wechatMchId ?? "";
-    form.wechatApiCertSerialNo = data.merchantSerialNumber ?? "";
-    form.wechatApiV3Key = data.apiV3Key ?? "";
-    form.wechatPayPublicKeyId = data.wechatPayPublicKeyId ?? null;
-    if (data.wechatPrivateKeyFile && data.wechatPrivateKeyName) {
-      const file = base64ToFile(data.wechatPrivateKeyFile, data.wechatPrivateKeyName);
-      form.wechatPrivateKeyFile = [{ name: file.name, raw: file, status: "success", uid: Date.now() } as UploadUserFile];
-    }
-    if (data.wechatPayPublicKeyFile && data.wechatPayPublicKeyFileName) {
-      const f = base64ToFile(data.wechatPayPublicKeyFile, data.wechatPayPublicKeyFileName);
-      form.wechatPayPublicKeyFile = [{ name: f.name, raw: f, status: "success", uid: Date.now() + 1 } as UploadUserFile];
-    }
+  // 后端可能同时返回三类配置,须分别回填;若用 else if 只会填到第一项,切换支付宝/银行会没有初始值
+  if (data.storeWechatId || data.wechatAppId) {
+    form.wechatAppid = String(data.storeWechatId ?? data.wechatAppId ?? "");
+    form.wechatMchld = String(data.storeWechatName ?? data.wechatMchId ?? "");
   }
-
-  if (data.appId) {
-    form.aliAppid = data.appId ?? "";
-    form.aliPrivateId = data.appSecretCert ?? "";
-    if (data.appPublicCert && data.appPublicCertName) {
-      const file = base64ToFile(data.appPublicCert, data.appPublicCertName);
-      form.appPublicCertFile = [{ name: file.name, raw: file, status: "success", uid: Date.now() } as UploadUserFile];
-    }
-    if (data.alipayPublicCert && data.alipayPublicCertName) {
-      const file = base64ToFile(data.alipayPublicCert, data.alipayPublicCertName);
-      form.alipayPublicCertFile = [{ name: file.name, raw: file, status: "success", uid: Date.now() + 1 } as UploadUserFile];
-    }
-    if (data.alipayRootCert && data.alipayRootCertName) {
-      const file = base64ToFile(data.alipayRootCert, data.alipayRootCertName);
-      form.alipayRootCertFile = [{ name: file.name, raw: file, status: "success", uid: Date.now() + 2 } as UploadUserFile];
-    }
-    if (!data.wechatAppId) form.accountType = "alipay";
+  if (data.storeAliId || data.appId) {
+    form.aliAppid = String(data.storeAliId ?? data.appId ?? "");
+    form.aliPrivateId = String(data.storeAliName ?? data.appSecretCert ?? "");
   }
 
   const bankNo = data.bankAccountNo ?? data.bankCardNo ?? data.settlementAccount;
   const bankNm = data.bankName ?? data.openingBankName ?? data.openingBank;
-  if (!data.wechatAppId && !data.appId && bankNo) {
-    form.accountType = "bank";
+  if (bankNo) {
     form.bankAccountNo = String(bankNo).replace(/\s/g, "");
     form.bankName = bankNm ? String(bankNm) : "";
   }
+
+  // 单选「当前展示哪一类」:有数据时优先微信 > 支付宝 > 银行(与保存时三选一一致)
+  if (data.storeWechatId || data.wechatAppId) {
+    form.accountType = "wechat";
+  } else if (data.storeAliId || data.appId) {
+    form.accountType = "alipay";
+  } else if (bankNo) {
+    form.accountType = "bank";
+  }
 };
 
 const submit = async () => {
@@ -371,55 +225,22 @@ const submit = async () => {
       }
 
       if (form.accountType === "alipay") {
-        const appPublicCertFile = (form.appPublicCertFile as UploadUserFile[])[0]?.raw as File | undefined;
-        const alipayPublicCertFile = (form.alipayPublicCertFile as UploadUserFile[])[0]?.raw as File | undefined;
-        const alipayRootCertFile = (form.alipayRootCertFile as UploadUserFile[])[0]?.raw as File | undefined;
-
-        if (!appPublicCertFile || !alipayPublicCertFile || !alipayRootCertFile) {
-          ElMessage.warning("请上传应用公钥证书、支付宝公钥证书和支付宝根证书");
-          return;
-        }
-
-        const res: any = await saveAlipayWithFiles(
-          {
-            storeUserId: String(storeUserId),
-            appId: form.aliAppid.trim(),
-            appSecretCert: form.aliPrivateId.trim()
-          },
-          appPublicCertFile,
-          alipayPublicCertFile,
-          alipayRootCertFile
-        );
-        if (res?.code === 200) ElMessage.success("保存成功");
+        const res: any = await saveAlipayWithFiles({
+          storeUserId,
+          storeAliId: form.aliAppid.trim(),
+          storeAliName: form.aliPrivateId.trim()
+        });
+        if (res?.code === 200 || res?.code === "200") ElMessage.success(res?.msg || "保存成功");
         else ElMessage.error(res?.msg || "保存失败");
         return;
       }
 
-      const privateKeyUpload = (form.wechatPrivateKeyFile as UploadUserFile[])[0];
-      const publicKeyUpload = (form.wechatPayPublicKeyFile as UploadUserFile[])[0];
-      const privateKeyFile = privateKeyUpload?.raw as File | undefined;
-      const publicKeyFile = publicKeyUpload?.raw as File | undefined;
-
-      if (!privateKeyFile || !publicKeyFile) {
-        ElMessage.warning("请上传私钥证书和公钥证书");
-        return;
-      }
-
-      const res: any = await saveWechatWithFiles(
-        {
-          storeUserId: String(storeUserId),
-          apiV3Key: form.wechatApiV3Key || "",
-          merchantSerialNumber: form.wechatApiCertSerialNo || "",
-          wechatAppId: form.wechatAppid || "",
-          wechatMchId: form.wechatMchld || "",
-          wechatMiniAppId: "",
-          wechatPayPublicKeyId: form.wechatPayPublicKeyId || "",
-          accountType: "wechat"
-        },
-        privateKeyFile,
-        publicKeyFile
-      );
-      if (res?.code === 200) ElMessage.success("保存成功");
+      const res: any = await saveWechatWithFiles({
+        storeUserId,
+        storeWechatId: form.wechatAppid.trim(),
+        storeWechatName: form.wechatMchld.trim()
+      });
+      if (res?.code === 200 || res?.code === "200") ElMessage.success(res?.msg || "保存成功");
       else ElMessage.error(res?.msg || "保存失败");
     } catch (e: any) {
       ElMessage.error(e?.message || "保存失败");
@@ -462,18 +283,4 @@ onMounted(async () => {
   line-height: 1.5;
   color: #909399;
 }
-.cert-upload :deep(.el-upload-dragger) {
-  padding: 20px;
-}
-.upload-inner {
-  color: var(--el-text-color-secondary);
-  text-align: center;
-  p {
-    margin: 8px 0 4px;
-    font-size: 14px;
-  }
-  span {
-    font-size: 12px;
-  }
-}
 </style>