PreferencesDrawer.vue 10 KB

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