Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion dashboard/src/components/platform/AddNewPlatform.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@
v-if="larkCreationMode === 'scan'"
class="registration-inline mt-3"
>
<v-text-field
:model-value="selectedPlatformConfig.id || ''"
:label="tm('registrationAction.platformIdLabel')"
:error="Boolean(scanPlatformIdError)"
:error-messages="scanPlatformIdError"
variant="outlined"
density="compact"
hide-details="auto"
class="registration-platform-id-field"
@update:model-value="setScanPlatformId"
/>
<PlatformRegistrationAction
:platform-config="selectedPlatformConfig"
:active="larkCreationMode === 'scan'"
Expand Down Expand Up @@ -139,6 +150,17 @@
v-if="dingtalkCreationMode === 'scan'"
class="registration-inline mt-3"
>
<v-text-field
:model-value="selectedPlatformConfig.id || ''"
:label="tm('registrationAction.platformIdLabel')"
:error="Boolean(scanPlatformIdError)"
:error-messages="scanPlatformIdError"
variant="outlined"
density="compact"
hide-details="auto"
class="registration-platform-id-field"
@update:model-value="setScanPlatformId"
/>
<PlatformRegistrationAction
:platform-config="selectedPlatformConfig"
:active="dingtalkCreationMode === 'scan'"
Expand Down Expand Up @@ -194,6 +216,17 @@
v-if="qqOfficialCreationMode === 'scan'"
class="registration-inline mt-3"
>
<v-text-field
:model-value="selectedPlatformConfig.id || ''"
:label="tm('registrationAction.platformIdLabel')"
:error="Boolean(scanPlatformIdError)"
:error-messages="scanPlatformIdError"
variant="outlined"
density="compact"
hide-details="auto"
class="registration-platform-id-field"
@update:model-value="setScanPlatformId"
/>
<PlatformRegistrationAction
:platform-config="selectedPlatformConfig"
:active="qqOfficialCreationMode === 'scan'"
Expand Down Expand Up @@ -228,8 +261,19 @@

<div
v-else-if="isWeixinOcPlatform"
class="weixin-oc-registration-inline mt-4"
class="registration-inline mt-4"
>
<v-text-field
:model-value="selectedPlatformConfig.id || ''"
:label="tm('registrationAction.platformIdLabel')"
:error="Boolean(scanPlatformIdError)"
:error-messages="scanPlatformIdError"
variant="outlined"
density="compact"
hide-details="auto"
class="registration-platform-id-field"
@update:model-value="setScanPlatformId"
/>
<PlatformRegistrationAction
:platform-config="selectedPlatformConfig"
:active="isWeixinOcPlatform"
Expand Down Expand Up @@ -834,6 +878,7 @@ export default {
larkCreationMode: "",
dingtalkCreationMode: "",
qqOfficialCreationMode: "",
scanPlatformIdCustomized: false,

aBConfigRadioVal: "0",
selectedAbConfId: "default",
Expand Down Expand Up @@ -1049,6 +1094,16 @@ export default {
this.selectedPlatformConfig?.type,
);
},
scanPlatformIdError() {
const platformId = String(this.selectedPlatformConfig?.id || "");
if (!platformId) {
return this.tm("registrationAction.platformIdRequired");
}
if (!this.isPlatformIdValid(platformId)) {
return this.tm("registrationAction.platformIdInvalid");
}
return "";
},
Comment on lines +1097 to +1106

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

建议复用已有的 isPlatformIdValid 方法来进行格式校验,避免重复编写 /[!:\s]/ 正则表达式,提高代码的可维护性。

    scanPlatformIdError() {
      const platformId = String(this.selectedPlatformConfig?.id || "");
      if (!platformId) {
        return this.tm("registrationAction.platformIdRequired");
      }
      if (!this.isPlatformIdValid(platformId)) {
        return this.tm("registrationAction.platformIdInvalid");
      }
      return "";
    },

},
watch: {
selectedPlatformType(newType) {
Expand All @@ -1059,11 +1114,13 @@ export default {
this.larkCreationMode = "";
this.dingtalkCreationMode = "";
this.qqOfficialCreationMode = "";
this.scanPlatformIdCustomized = false;
} else {
this.selectedPlatformConfig = null;
this.larkCreationMode = "";
this.dingtalkCreationMode = "";
this.qqOfficialCreationMode = "";
this.scanPlatformIdCustomized = false;
}
},
selectedAbConfId(newConfigId) {
Expand Down Expand Up @@ -1151,6 +1208,7 @@ export default {
this.larkCreationMode = "";
this.dingtalkCreationMode = "";
this.qqOfficialCreationMode = "";
this.scanPlatformIdCustomized = false;

this.aBConfigRadioVal = "0";
this.selectedAbConfId = "default";
Expand Down Expand Up @@ -1467,6 +1525,14 @@ export default {
this.$emit("show-toast", { message: message, type: "error" });
},

setScanPlatformId(value) {
if (!this.selectedPlatformConfig) {
return;
}
this.scanPlatformIdCustomized = true;
this.selectedPlatformConfig.id = String(value || "");
},
Comment on lines +1528 to +1534

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

在用户输入过程中,使用 .trim() 会导致无法在输入框末尾输入空格(输入空格会被立即清除,从而可能导致光标跳转或无法触发“不能包含空格”的校验提示)。建议移除 .trim(),让校验器(scanPlatformIdError)来处理空格校验,或者仅在保存时进行 trim 处理。

    setScanPlatformId(value) {
      if (!this.selectedPlatformConfig) {
        return;
      }
      this.scanPlatformIdCustomized = true;
      this.selectedPlatformConfig.id = String(value || "");
    },


buildRandomPlatformIdSuffix() {
const letters = "abcdefghijklmnopqrstuvwxyz";
let suffix = "_";
Expand All @@ -1487,6 +1553,9 @@ export default {
if (!this.selectedPlatformConfig || !data) {
return;
}
if (this.scanPlatformIdCustomized) {
return;
}
const currentId = String(this.selectedPlatformConfig.id || "").trim();
const platformType = this.selectedPlatformConfig.type;
if (!currentId) {
Expand Down Expand Up @@ -1963,8 +2032,14 @@ export default {

.registration-inline {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
width: 320px;
gap: 8px;
}

.registration-platform-id-field {
width: 300px;
}
</style>
3 changes: 3 additions & 0 deletions dashboard/src/i18n/locales/en-US/features/platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@
"created": "Setup Complete",
"startFailed": "Failed to start QR setup",
"pollFailed": "Failed to poll QR setup status",
"platformIdLabel": "Bot ID",
"platformIdRequired": "Bot ID is required",
"platformIdInvalid": "Bot ID cannot contain spaces, ':' or '!'",
"mode": {
"title": "Choose setup method",
"scan": "One-click QR setup",
Expand Down
3 changes: 3 additions & 0 deletions dashboard/src/i18n/locales/ru-RU/features/platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@
"created": "Настройка завершена",
"startFailed": "Не удалось начать QR настройку",
"pollFailed": "Не удалось проверить статус QR настройки",
"platformIdLabel": "ID бота",
"platformIdRequired": "ID бота обязателен",
"platformIdInvalid": "ID бота не может содержать пробелы, ':' или '!'",
"mode": {
"title": "Выберите способ создания",
"scan": "Создать через QR",
Expand Down
3 changes: 3 additions & 0 deletions dashboard/src/i18n/locales/zh-CN/features/platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@
"created": "创建成功",
"startFailed": "发起扫码创建失败",
"pollFailed": "获取扫码创建状态失败",
"platformIdLabel": "机器人 ID",
"platformIdRequired": "机器人 ID 不能为空",
"platformIdInvalid": "机器人 ID 不能包含空格、':' 或 '!'",
"mode": {
"title": "选择创建方式",
"scan": "扫码一键创建",
Expand Down
Loading