Skip to content

Commit 518be7c

Browse files
committed
feat: 脚本操作支持收起内容
1 parent fc4ad55 commit 518be7c

2 files changed

Lines changed: 116 additions & 38 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store-front-end",
3-
"version": "2.17.34",
3+
"version": "2.17.35",
44
"private": true,
55
"scripts": {
66
"dev": "vite --host",

src/views/editor/components/Script.vue

Lines changed: 115 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,56 @@
11
<template>
22
<div class="editor-action-card">
3-
<p class="des-label">
4-
{{ $t(`editorPage.subConfig.nodeActions['${type}'].des[0]`) }}
3+
<div class="type-row">
4+
<button
5+
type="button"
6+
class="content-fold-toggle"
7+
:aria-expanded="!isContentFolded"
8+
:aria-label="
9+
isContentFolded
10+
? $t('moreSettingPage.editorDisplayMode.expanded')
11+
: $t('moreSettingPage.editorDisplayMode.collapsed')
12+
"
13+
@click="toggleContentFold"
14+
>
15+
<nut-icon
16+
:name="isContentFolded ? 'rect-right' : 'rect-down'"
17+
size="12px"
18+
/>
19+
<span>
20+
{{ $t(`editorPage.subConfig.nodeActions['${type}'].des[0]`) }}
21+
</span>
22+
</button>
523
<a
24+
class="doc-link"
625
href="https://github.com/sub-store-org/Sub-Store/wiki/%E8%84%9A%E6%9C%AC%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E"
726
target="_blank"
827
>
928
{{ $t("subPage.panel.tips.ok") }}
1029
</a>
11-
</p>
12-
<nut-radiogroup v-model="value.mode" direction="horizontal">
13-
<nut-radio v-for="(key, index) in modeList" :key="index" :label="key">
14-
{{
15-
$t(`editorPage.subConfig.nodeActions['${type}'].options[${index}]`)
16-
}}
17-
</nut-radio>
18-
</nut-radiogroup>
19-
20-
<div v-if="value.mode === 'link'" class="input-wrapper">
21-
<nut-textarea
22-
v-model="value.content"
23-
:placeholder="
24-
$t(`editorPage.subConfig.nodeActions['${type}'].placeholder`)
25-
"
26-
:rows="5"
27-
autosize
28-
@blur="handleLinkValueChange"
29-
/>
3030
</div>
31-
<div
32-
v-if="value.mode === 'script'"
33-
style="
34-
margin-left: -16px;
35-
margin-right: -16px;
36-
max-height: 80vh;
37-
overflow: auto;
38-
"
39-
>
40-
<cmView :id="id" :is-read-only="false" />
31+
<div v-show="!isContentFolded">
32+
<nut-radiogroup v-model="value.mode" direction="horizontal">
33+
<nut-radio v-for="(key, index) in modeList" :key="index" :label="key">
34+
{{
35+
$t(`editorPage.subConfig.nodeActions['${type}'].options[${index}]`)
36+
}}
37+
</nut-radio>
38+
</nut-radiogroup>
39+
40+
<div v-if="value.mode === 'link'" class="input-wrapper">
41+
<nut-textarea
42+
v-model="value.content"
43+
:placeholder="
44+
$t(`editorPage.subConfig.nodeActions['${type}'].placeholder`)
45+
"
46+
:rows="5"
47+
autosize
48+
@blur="handleLinkValueChange"
49+
/>
50+
</div>
51+
<div v-if="value.mode === 'script'" class="local-content-section">
52+
<cmView :id="id" :is-read-only="false" />
53+
</div>
4154
</div>
4255

4356
<!-- 参数编辑控制部分 -->
@@ -96,10 +109,15 @@
96109
import { Dialog } from "@nutui/nutui";
97110
import { inject, onMounted, reactive, ref, watch } from "vue";
98111
import { useI18n } from "vue-i18n";
112+
import { useRoute } from "vue-router";
99113
100114
import ParamsEditor from "@/components/ParamsEditor.vue";
101115
import { usePopupRoute } from "@/hooks/usePopupRoute";
102116
import { useCodeStore } from "@/store/codeStore";
117+
import {
118+
getEditorIsFolded,
119+
setEditorFoldState,
120+
} from "@/utils/editorFoldState";
103121
import cmView from "@/views/editCode/cmView.vue";
104122
105123
const { type, id, sourceType } = defineProps<{
@@ -111,10 +129,33 @@ const { type, id, sourceType } = defineProps<{
111129
const cmStore = useCodeStore();
112130
113131
const { t } = useI18n();
132+
const route = useRoute();
114133
115134
const form = inject<Sub | Collection>("form");
116135
117136
const modeList = ["link", "script"];
137+
const SCRIPT_CONTENT_FOLD_STORAGE_KEY = "script-local-content-fold";
138+
139+
const getContentFoldPath = (path = route.path) => {
140+
return [path, sourceType || "default", type, id].join(":");
141+
};
142+
143+
const isContentFolded = ref(
144+
getEditorIsFolded(
145+
SCRIPT_CONTENT_FOLD_STORAGE_KEY,
146+
getContentFoldPath(),
147+
false,
148+
),
149+
);
150+
151+
const toggleContentFold = () => {
152+
isContentFolded.value = !isContentFolded.value;
153+
setEditorFoldState(
154+
SCRIPT_CONTENT_FOLD_STORAGE_KEY,
155+
getContentFoldPath(),
156+
isContentFolded.value,
157+
);
158+
};
118159
119160
const showKeyValue = ref(false);
120161
@@ -587,6 +628,17 @@ watch(
587628
},
588629
);
589630
631+
watch(
632+
() => route.path,
633+
(path) => {
634+
isContentFolded.value = getEditorIsFolded(
635+
SCRIPT_CONTENT_FOLD_STORAGE_KEY,
636+
getContentFoldPath(path),
637+
false,
638+
);
639+
},
640+
);
641+
590642
watch(
591643
() => cmStore.EditCode[id],
592644
(newCode) => {
@@ -596,18 +648,38 @@ watch(
596648
</script>
597649

598650
<style lang="scss" scoped>
599-
.des-label {
600-
font-size: 12px;
651+
.type-row {
601652
margin-bottom: 8px;
653+
display: flex;
654+
align-items: center;
655+
gap: 6px;
656+
}
657+
.content-fold-toggle {
658+
border: 0;
659+
padding: 0;
660+
background: transparent;
602661
color: var(--comment-text-color);
662+
display: inline-flex;
663+
align-items: center;
664+
justify-content: center;
665+
height: 18px;
666+
gap: 6px;
667+
font-size: 12px;
668+
cursor: pointer;
669+
flex-shrink: 0;
603670
604-
&:not(:first-child) {
605-
margin-top: 16px;
671+
&:focus {
672+
outline: none;
606673
}
607-
a {
608-
color: var(--primary-color);
674+
675+
svg {
676+
color: var(--unimportant-icon-color);
609677
}
610678
}
679+
.doc-link {
680+
color: var(--primary-color);
681+
font-size: 12px;
682+
}
611683
612684
.nut-radiogroup {
613685
width: 100%;
@@ -631,6 +703,12 @@ watch(
631703
}
632704
}
633705
}
706+
.local-content-section {
707+
margin-left: -16px;
708+
margin-right: -16px;
709+
max-height: 80vh;
710+
overflow: auto;
711+
}
634712
.input-wrapper-title {
635713
display: flex;
636714
align-items: center;

0 commit comments

Comments
 (0)