mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-10 07:48:12 +00:00
perf: 优化翻译消息
This commit is contained in:
parent
b467dc55e5
commit
34cfd1e344
@ -1792,6 +1792,8 @@ class DialogController extends AbstractController
|
||||
* @apiName msg__translation
|
||||
*
|
||||
* @apiParam {Number} msg_id 消息ID
|
||||
* @apiParam {Number} [force] 强制翻译(1是、0否)
|
||||
* - 默认不强制翻译,已翻译过的消息不再翻译
|
||||
* @apiParam {String} [language] 目标语言,默认当前语言
|
||||
*
|
||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||
@ -1803,6 +1805,7 @@ class DialogController extends AbstractController
|
||||
User::auth();
|
||||
//
|
||||
$msg_id = intval(Request::input("msg_id"));
|
||||
$force = intval(Request::input("force"));
|
||||
$language = Base::inputOrHeader('language');
|
||||
$targetLanguage = Doo::getLanguages($language);
|
||||
//
|
||||
@ -1820,13 +1823,20 @@ class DialogController extends AbstractController
|
||||
//
|
||||
$row = WebSocketDialogMsgTranslate::whereMsgId($msg_id)->whereLanguage($language)->first();
|
||||
if ($row) {
|
||||
return Base::retSuccess("success", $row->only(['msg_id', 'language', 'content']));
|
||||
if ($force) {
|
||||
$row->delete();
|
||||
} else {
|
||||
return Base::retSuccess("success", $row->only(['msg_id', 'language', 'content']));
|
||||
}
|
||||
}
|
||||
//
|
||||
$msgData = Base::json2array($msg->getRawOriginal('msg'));
|
||||
if (empty($msgData['text'])) {
|
||||
return Base::retError("消息内容为空");
|
||||
}
|
||||
if ($msg->type === 'text' && $msgData['type'] === 'md') {
|
||||
$msgData['text'] = preg_replace('/:::\s*reasoning.*?:::/s', '', $msgData['text']);
|
||||
}
|
||||
$res = Extranet::openAItranslations($msgData['text'], $targetLanguage);
|
||||
if (Base::isError($res)) {
|
||||
return $res;
|
||||
|
||||
@ -1924,3 +1924,4 @@ API请求的基础URL路径,如果没有请留空
|
||||
|
||||
欢迎词
|
||||
仪表盘欢迎词,(*)代表用户昵称
|
||||
思考过程
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
<div class="divider-label translation-label" @click="viewText">{{ translation.label }}</div>
|
||||
<span></span>
|
||||
</div>
|
||||
<DialogMarkdown v-if="msg.type === 'md'" :text="translation.content"/>
|
||||
<DialogMarkdown v-if="msg.type === 'md'" :text="translation.content" class="content-translation"/>
|
||||
<pre v-else v-html="$A.formatTextMsg(translation.content, userId)"></pre>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
@ -3197,7 +3197,7 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
onTranslation() {
|
||||
onTranslation(language = undefined) {
|
||||
if (!this.actionPermission(this.operateItem, 'translation')) {
|
||||
return;
|
||||
}
|
||||
@ -3206,12 +3206,22 @@ export default {
|
||||
if (this.isLoad(key)) {
|
||||
return;
|
||||
}
|
||||
let force = 0;
|
||||
if (language === 'hidden') {
|
||||
this.$store.dispatch("removeTranslation", key);
|
||||
return;
|
||||
} else if (language === 'retranslation') {
|
||||
this.$store.dispatch("removeTranslation", key);
|
||||
language = undefined;
|
||||
force = 1;
|
||||
}
|
||||
this.$store.dispatch("setLoad", key)
|
||||
this.$store.dispatch("call", {
|
||||
url: 'dialog/msg/translation',
|
||||
data: {
|
||||
msg_id,
|
||||
language: this.cacheTranslationLanguage
|
||||
force,
|
||||
language: language || this.cacheTranslationLanguage
|
||||
},
|
||||
}).then(({data}) => {
|
||||
this.$store.dispatch("saveTranslation", Object.assign(data, {key}));
|
||||
@ -3356,14 +3366,20 @@ export default {
|
||||
label: languageList[item],
|
||||
value: item
|
||||
}))
|
||||
list.push(...[
|
||||
{label: '重新翻译', value: 'retranslation', divided: true},
|
||||
{label: '隐藏翻译', value: 'hidden'},
|
||||
])
|
||||
this.$store.state.menuOperation = {
|
||||
event,
|
||||
list,
|
||||
active: this.cacheTranslationLanguage,
|
||||
scrollHide: true,
|
||||
onUpdate: async (language) => {
|
||||
await this.$store.dispatch("setTranslationLanguage", language);
|
||||
this.onTranslation();
|
||||
if (languageList[language]) {
|
||||
await this.$store.dispatch("setTranslationLanguage", language);
|
||||
}
|
||||
this.onTranslation(language);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
10
resources/assets/js/store/actions.js
vendored
10
resources/assets/js/store/actions.js
vendored
@ -3594,6 +3594,16 @@ export default {
|
||||
$A.IDBSave("cacheTranslations", state.cacheTranslations.slice(-200))
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除翻译
|
||||
* @param state
|
||||
* @param key
|
||||
*/
|
||||
removeTranslation({state}, key) {
|
||||
state.cacheTranslations = state.cacheTranslations.filter(item => item.key != key)
|
||||
$A.IDBSave("cacheTranslations", state.cacheTranslations.slice(-200))
|
||||
},
|
||||
|
||||
/**
|
||||
* 设置翻译语言
|
||||
* @param state
|
||||
|
||||
@ -2171,6 +2171,24 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.content-translation {
|
||||
.apply-reasoning {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.apply-create-task {
|
||||
ul {
|
||||
li:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.apply-button {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body:not(.window-touch) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user