PreferencesDrawer.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <script setup lang="ts">
  2. import {
  3. NColorPicker,
  4. NDivider,
  5. NDrawer,
  6. NDrawerContent,
  7. NSwitch,
  8. useModal,
  9. NScrollbar,
  10. } from 'naive-ui'
  11. import { storeToRefs } from 'pinia'
  12. import { h, ref } from 'vue'
  13. import { ButtonAnimation, ButtonAnimationProvider } from '@/components'
  14. import { useComponentThemeOverrides, useInjection, usePersonalization } from '@/composables'
  15. import { mediaQueryInjectionKey } from '@/injection'
  16. import { usePreferencesStore, useSystemStore } from '@/stores'
  17. import { ccAPCA } from '@/utils/chromaHelper'
  18. import twColors from '@/utils/tailwindColor'
  19. import twc from '@/utils/tailwindColor'
  20. import LayoutThumbnail from './component/LayoutThumbnail.vue'
  21. import NoiseModal from './component/NoiseModal.vue'
  22. import WatermarkModal from './component/WatermarkModal.vue'
  23. const { isSmallScreen } = useInjection(mediaQueryInjectionKey)
  24. const preferencesStore = usePreferencesStore()
  25. const { modify, reset } = preferencesStore
  26. const {
  27. enableNavigationTransition,
  28. enableTextSelect,
  29. navigationMode,
  30. showTopLoadingBar,
  31. showLogo,
  32. showNavigation,
  33. showBreadcrumb,
  34. showTabs,
  35. showTabClose,
  36. showFooter,
  37. showWatermark,
  38. showNoise,
  39. sidebarMenu,
  40. } = storeToRefs(preferencesStore)
  41. const systemStore = useSystemStore()
  42. const { color, setColor } = usePersonalization()
  43. const modal = useModal()
  44. const { scrollbarInModal } = useComponentThemeOverrides()
  45. const showDrawer = ref(false)
  46. const colorSwatches = [
  47. twColors.red[500],
  48. twColors.orange[500],
  49. twColors.amber[500],
  50. twColors.yellow[500],
  51. twColors.lime[500],
  52. twColors.green[500],
  53. twColors.emerald[500],
  54. twColors.teal[500],
  55. twColors.cyan[500],
  56. twColors.sky[500],
  57. twColors.blue[500],
  58. twColors.indigo[500],
  59. twColors.violet[500],
  60. twColors.purple[500],
  61. twColors.fuchsia[500],
  62. twColors.pink[500],
  63. ]
  64. const showWatermarkModal = () => {
  65. modal.create({
  66. title: '修改水印信息',
  67. preset: 'dialog',
  68. content: () =>
  69. h(
  70. NScrollbar,
  71. {
  72. themeOverrides: scrollbarInModal.value,
  73. style: {
  74. maxHeight: '400px',
  75. },
  76. contentClass: 'pr-3 py-6',
  77. },
  78. {
  79. default: () => h(WatermarkModal),
  80. },
  81. ),
  82. closable: true,
  83. draggable: true,
  84. showIcon: false,
  85. zIndex: 99999,
  86. })
  87. }
  88. const showNoiseModal = () => {
  89. modal.create({
  90. title: '修改磨砂细腻度',
  91. preset: 'dialog',
  92. content: () => h(NoiseModal),
  93. closable: true,
  94. draggable: true,
  95. showIcon: false,
  96. zIndex: 99999,
  97. })
  98. }
  99. </script>
  100. <template>
  101. <div>
  102. <ButtonAnimation
  103. @click="showDrawer = true"
  104. title="侧边栏"
  105. >
  106. <span class="iconify rotate-180 ph--sidebar-simple-duotone" />
  107. </ButtonAnimation>
  108. <ButtonAnimationProvider>
  109. <NDrawer
  110. v-model:show="showDrawer"
  111. :auto-focus="false"
  112. :width="320"
  113. :theme-overrides="{
  114. footerPadding: '14px 16px',
  115. }"
  116. >
  117. <NDrawerContent :native-scrollbar="false">
  118. <template #header>
  119. <div class="flex items-center gap-x-1">
  120. <span>系统设定</span>
  121. <ButtonAnimation
  122. animation="rotate"
  123. @click="reset"
  124. >
  125. <span class="iconify ph--arrow-clockwise" />
  126. </ButtonAnimation>
  127. </div>
  128. </template>
  129. <div>
  130. <NDivider>主题颜色</NDivider>
  131. <NColorPicker
  132. v-bind="$attrs"
  133. :default-value="color"
  134. :swatches="colorSwatches"
  135. @update-value="setColor"
  136. >
  137. <template #label="currentColor">
  138. <span
  139. :style="
  140. currentColor && {
  141. color: ccAPCA(currentColor, twc.neutral[150], twc.neutral[950], '#fff'),
  142. }
  143. "
  144. >{{ currentColor }}</span
  145. >
  146. </template>
  147. </NColorPicker>
  148. </div>
  149. <div>
  150. <NDivider>导航模式</NDivider>
  151. <LayoutThumbnail />
  152. </div>
  153. <div>
  154. <NDivider>布局相关</NDivider>
  155. <div class="flex flex-col gap-y-1.5">
  156. <div class="flex items-center justify-between">
  157. <span>展开侧边菜单</span>
  158. <NSwitch
  159. :value="sidebarMenu.collapsed"
  160. :checked-value="false"
  161. :unchecked-value="true"
  162. :disabled="isSmallScreen || navigationMode !== 'sidebar'"
  163. @update-value="
  164. (value) =>
  165. modify({
  166. sidebarMenu: {
  167. collapsed: value,
  168. },
  169. })
  170. "
  171. />
  172. </div>
  173. <div class="flex items-center justify-between">
  174. <span>显示顶部加载条</span>
  175. <NSwitch
  176. :value="showTopLoadingBar"
  177. @update-value="
  178. (value) =>
  179. modify({
  180. showTopLoadingBar: value,
  181. })
  182. "
  183. />
  184. </div>
  185. <div class="flex items-center justify-between">
  186. <span>显示Logo</span>
  187. <NSwitch
  188. :value="showLogo"
  189. @update-value="
  190. (value) =>
  191. modify({
  192. showLogo: value,
  193. })
  194. "
  195. />
  196. </div>
  197. <div class="flex items-center justify-between">
  198. <span>显示导航按钮</span>
  199. <NSwitch
  200. :value="showNavigation"
  201. :disabled="isSmallScreen || navigationMode !== 'sidebar'"
  202. @update-value="
  203. (value) =>
  204. modify({
  205. showNavigation: value,
  206. })
  207. "
  208. />
  209. </div>
  210. <div class="flex items-center justify-between">
  211. <span>显示面包屑</span>
  212. <NSwitch
  213. :value="showBreadcrumb"
  214. :disabled="isSmallScreen || navigationMode !== 'sidebar'"
  215. @update-value="
  216. (value) =>
  217. modify({
  218. showBreadcrumb: value,
  219. })
  220. "
  221. />
  222. </div>
  223. <div class="flex items-center justify-between">
  224. <span>显示标签页</span>
  225. <NSwitch
  226. :value="showTabs"
  227. :disabled="isSmallScreen"
  228. @update-value="
  229. (value) =>
  230. modify({
  231. showTabs: value,
  232. })
  233. "
  234. />
  235. </div>
  236. <div class="flex items-center justify-between">
  237. <span>常显标签关闭按钮</span>
  238. <NSwitch
  239. :value="showTabClose"
  240. :disabled="isSmallScreen"
  241. @update-value="
  242. (value) =>
  243. modify({
  244. showTabClose: value,
  245. })
  246. "
  247. />
  248. </div>
  249. <div class="flex items-center justify-between">
  250. <span>显示底部</span>
  251. <NSwitch
  252. :value="showFooter"
  253. :disabled="isSmallScreen"
  254. @update-value="
  255. (value) =>
  256. modify({
  257. showFooter: value,
  258. })
  259. "
  260. />
  261. </div>
  262. </div>
  263. </div>
  264. <div>
  265. <NDivider>页面相关</NDivider>
  266. <div class="flex items-center justify-between">
  267. <div class="flex items-center gap-x-1">
  268. <span>显示水印</span>
  269. <ButtonAnimation
  270. size="small"
  271. @click="showWatermarkModal"
  272. label="修改"
  273. >
  274. <span class="iconify size-4 ph--pencil-simple-line" />
  275. </ButtonAnimation>
  276. </div>
  277. <NSwitch
  278. :value="showWatermark"
  279. @update-value="
  280. (value) =>
  281. modify({
  282. showWatermark: value,
  283. })
  284. "
  285. />
  286. </div>
  287. <div class="flex items-center justify-between">
  288. <div class="flex items-center gap-x-1">
  289. <span>显示磨砂效果</span>
  290. <ButtonAnimation
  291. size="small"
  292. :duration="3000"
  293. @click="showNoiseModal"
  294. label="修改"
  295. >
  296. <span class="iconify size-4 ph--pencil-simple-line" />
  297. </ButtonAnimation>
  298. </div>
  299. <NSwitch
  300. :value="showNoise"
  301. @update-value="
  302. (value) =>
  303. modify({
  304. showNoise: value,
  305. })
  306. "
  307. />
  308. </div>
  309. <div class="flex flex-col gap-y-1.5">
  310. <div class="flex items-center justify-between">
  311. <span>启用导航过渡效果</span>
  312. <NSwitch
  313. :value="enableNavigationTransition"
  314. :disabled="isSmallScreen"
  315. @update-value="
  316. (value) =>
  317. modify({
  318. enableNavigationTransition: value,
  319. })
  320. "
  321. />
  322. </div>
  323. <div class="flex items-center justify-between">
  324. <span>文字可选中</span>
  325. <NSwitch
  326. :value="enableTextSelect"
  327. @update-value="
  328. (value) =>
  329. modify({
  330. enableTextSelect: value,
  331. })
  332. "
  333. />
  334. </div>
  335. </div>
  336. </div>
  337. <template #footer>
  338. <div class="flex w-full items-center justify-between">
  339. <div class="flex items-center gap-x-1">
  340. <span class="iconify size-5 ph--gear-fine" />
  341. <span class="leading-4">当前版本</span>
  342. </div>
  343. <span class="leading-4">{{ systemStore.version }}</span>
  344. </div>
  345. </template>
  346. </NDrawerContent>
  347. </NDrawer>
  348. </ButtonAnimationProvider>
  349. </div>
  350. </template>