-
Notifications
You must be signed in to change notification settings - Fork 1
/
PublishSetting.vue
386 lines (363 loc) · 12.6 KB
/
PublishSetting.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!--
- Copyright (c) 2023, Terwer . All rights reserved.
- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-
- This code is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License version 2 only, as
- published by the Free Software Foundation. Terwer designates this
- particular file as subject to the "Classpath" exception as provided
- by Terwer in the LICENSE file that accompanied this code.
-
- This code is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- version 2 for more details (a copy is included in the LICENSE file that
- accompanied this code).
-
- You should have received a copy of the GNU General Public License version
- 2 along with this work; if not, write to the Free Software Foundation,
- Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-
- Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
- or visit www.terwer.space if you need additional information or have any
- questions.
-->
<script setup lang="ts">
import { markRaw, onMounted, reactive } from "vue"
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import { Delete, Tools } from "@element-plus/icons-vue"
import { useSettingStore } from "~/src/stores/useSettingStore.ts"
import { SypConfig } from "~/syp.config.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { JsonUtil } from "zhi-common"
import {
AuthMode,
DynamicConfig,
DynamicJsonCfg,
PlatformType,
} from "~/src/components/set/publish/platform/dynamicConfig.ts"
import { DYNAMIC_CONFIG_KEY } from "~/src/utils/constants.ts"
import { useRouter } from "vue-router"
import { usePlatformDefine } from "~/src/composables/usePlatformDefine.ts"
import { ElMessage, ElMessageBox } from "element-plus"
import { svgIcons } from "~/src/utils/svgIcons.ts"
const logger = createAppLogger("publish-setting")
// uses
const { t } = useVueI18n()
const router = useRouter()
const { getSetting, updateSetting } = useSettingStore()
const { platformTypeList } = usePlatformDefine()
// datas
const formData = reactive({
setting: {} as typeof SypConfig,
showAdd: false,
platformTypeList: platformTypeList,
dynamicConfigArray: [] as DynamicConfig[],
})
// methods
const handleShowPlatform = () => {
formData.showAdd = true
}
const handleHidePlatform = () => {
formData.showAdd = false
}
const handleAddPlatformStep = (type: PlatformType) => {
if (type === PlatformType.Custom) {
ElMessage.error("自定义 HTTP 协议暂未实现,敬请期待")
return
}
router.push({
path: `/setting/platform/quickadd/${type}`,
query: {
showBack: "true",
},
})
}
const handleSinglePlatformSetting = (key: string) => {
router.push({
path: `/setting/platform/single/${key}`,
query: {
showBack: "true",
},
})
}
const handleSinglePlatformDelete = (cfg: DynamicConfig) => {
ElMessageBox.confirm(`确认要删除【${cfg.platformName}】吗,所有与此平台相关的配置都将永久删除?`, "温馨提示", {
type: "error",
icon: markRaw(Delete),
confirmButtonText: t("main.opt.ok"),
cancelButtonText: t("main.opt.cancel"),
})
.then((action) => {
ElMessage({
type: "info",
message: `action: ${action}`,
})
})
.catch(() => {})
}
const handleChangeName = (cfg: DynamicConfig) => {
alert("修改平台名称")
}
const initPage = async () => {
formData.setting = await getSetting()
logger.info("get setting from platform setting", formData.setting)
const dynJsonCfg = JsonUtil.safeParse<DynamicJsonCfg>(formData.setting[DYNAMIC_CONFIG_KEY], {} as DynamicJsonCfg)
// 默认展示通用平台
formData.dynamicConfigArray = dynJsonCfg.totalCfg || []
logger.debug("dynamic init page=>", formData.dynamicConfigArray)
}
// lifecycles
onMounted(async () => {
await initPage()
})
</script>
<template>
<div class="publish-setting-body">
<el-row :gutter="20" class="row-item">
<el-col :span="2" class="col-item">
<el-menu class="publish-setting-left-menu">
<el-menu-item
:class="formData.showAdd ? 'left-menu-item' : 'left-menu-item menu-item-selected'"
@click="handleHidePlatform"
>
<template #title>
<span> {{ t("service.tab.publish.setting") }} </span>
</template>
</el-menu-item>
<el-menu-item
:class="!formData.showAdd ? 'left-menu-item' : 'left-menu-item menu-item-selected'"
@click="handleShowPlatform"
>
<template #title>
<span> + {{ t("setting.platform.add") }} </span>
</template>
</el-menu-item>
</el-menu>
</el-col>
<el-col :span="22" class="col-item">
<div class="publish-setting-right-content">
<div v-if="formData.showAdd">
<el-row :gutter="20" class="row-item">
<el-col
v-for="p in formData.platformTypeList"
:key="p.type"
:span="24"
class="col-item"
@click="handleAddPlatformStep(p.type)"
>
<el-card class="platform-right-card">
<img :src="p.img" class="image" alt="" />
<div class="right-card-text">
<span>{{ p.title }}</span>
<div>
<div class="text-desc">{{ p.description }}</div>
<div class="add-btn">
<el-button size="small" type="primary">{{ t("setting.platform.add.this") }}</el-button>
</div>
</div>
</div>
</el-card>
</el-col>
</el-row>
</div>
<div v-else-if="formData.dynamicConfigArray.length === 0">
<el-alert class="no-tip" type="error" :title="t('platform.must.select.one')"></el-alert>
</div>
<div v-else>
<div class="publish-right-setting">
<el-row :gutter="20" class="platform-list">
<el-col
v-for="platform in formData.dynamicConfigArray"
:key="platform.platformKey"
:span="6"
class="platform-item-box"
>
<div class="platform-item">
<el-icon class="item-left-icon">
<span class="item-icon" v-html="platform.platformIcon"></span>
</el-icon>
<div class="item-right">
<div class="text">
<el-badge
:value="platform.isAuth ? '已授权' : '未授权'"
class="badge-item"
:type="platform.isAuth ? 'success' : 'warning'"
>
<span>{{ platform.platformName }}</span>
<span class="name-edit" @click="handleChangeName(platform)">
<el-icon> <span v-html="svgIcons.iconIFEdit"></span> </el-icon>
</span>
<el-text
:type="platform.authMode === AuthMode.API ? 'primary' : 'info'"
class="auth-mode-text"
>
{{ platform.authMode === AuthMode.API ? "API授权" : "网页授权" }}
</el-text>
</el-badge>
</div>
<div class="actions">
<el-switch
v-model="platform.isEnabled"
inline-prompt
size="small"
class="action-btn action-switch"
active-text="已启用"
inactive-text="未启用"
></el-switch>
<el-text
v-if="platform.isEnabled && platform.authMode === AuthMode.API"
class="action-btn action-setting"
@click="handleSinglePlatformSetting(platform.platformKey)"
>
<el-icon> <Tools /> </el-icon>设置
</el-text>
<el-text
v-if="!platform.isEnabled"
class="action-btn action-del"
@click="handleSinglePlatformDelete(platform)"
>
<el-icon> <Delete /> </el-icon>删除
</el-text>
</div>
</div>
</div>
</el-col>
</el-row>
<el-row>
<el-col>
<div class="right-setting-tips">
<div class="el-alert el-alert--warning is-light" role="alert">
<div class="el-alert__content">
<div class="el-alert__title">
<div>{{ t("setting.platform.right.tips0") }}</div>
<div>{{ t("setting.platform.right.tips1") }}</div>
<div>{{ t("setting.platform.right.tips2") }}</div>
<div>{{ t("setting.platform.right.tips3") }}</div>
<div>{{ t("setting.platform.right.tips4") }}</div>
</div>
</div>
</div>
<div class="tips-form">
<a
href="https://terwergreen.feishu.cn/share/base/form/shrcnGRdThUiqnhBg15xgclMM0c"
target="_blank"
>
发布工具平台适配跟踪表
</a>
</div>
</div>
</el-col>
</el-row>
</div>
</div>
</div>
</el-col>
</el-row>
</div>
</template>
<style scoped lang="stylus">
$icon_size = 32px
.publish-setting-body
margin-left 10px
margin-top 10px
.publish-setting-left-menu
text-align center
.left-menu-item
justify-content center
height 36px
.menu-item-selected
color var(--el-fill-color-blank)
background var(--el-color-primary)
html[class="dark"]
.menu-item-selected
color var(--el-button-text-color)
.publish-setting-right-content
.right-setting-tips
text-align left
padding-left 10px
padding-right 10px
.tips-form
font-size 12px
margin-top 14px
.no-tip
margin 0 10px
padding-left 0
width calc(100% - 30px)
.publish-right-setting
.platform-list
margin-bottom 10px
margin-left 6px !important
margin-right 6px !important
.platform-item-box
margin-bottom 28px
text-align left
.platform-item
.item-left-icon
//color var(--el-color-primary)
width $icon_size
height $icon_size
margin-top -14px
vertical-align middle
:deep(.item-icon svg)
width $icon_size
height $icon_size
.item-right
display inline-block
margin-left 10px
text-align left
.text
color var(--el-button-text-color)
font-size 12px
margin-bottom 2px
.auth-mode-text
font-size 12px
margin-left 16px
.name-edit
color var(--el-color-primary)
margin-left 4px
cursor pointer
.actions
.action-btn
margin-right 10px
.action-switch
font-size 12px
.action-setting
font-size 12px
cursor pointer
&:hover
color var(--el-color-primary)
.action-del
color red
font-size 12px
cursor pointer
&:hover
color var(--el-color-primary)
.row-item
margin 0 !important
padding 0 !important
text-align center
.col-item
margin 0 !important
padding 0 !important
.platform-right-card
margin 0
margin-left 10px
margin-right 10px
margin-bottom 10px
padding 0
img
width 160px
height 160px
.right-card-text
padding 0 10px 10px 10px
display inline-block
vertical-align top
line-height 32px
width calc(100% - 180px)
.text-desc
font-size 12px
line-height 18px
.add-btn
margin-top 12px
</style>