book-display.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view class="settings-container">
  3. <!-- 设置列表 -->
  4. <u-cell-group :border="false" class="settings-group">
  5. <u-cell title="是否展示回收价" :border-bottom="true">
  6. <template #right-icon>
  7. <u-switch v-model="settings.showRecyclePrice" activeColor="#4cd964"></u-switch>
  8. </template>
  9. </u-cell>
  10. <u-cell title="是否展示回收状态" :border-bottom="true">
  11. <template #right-icon>
  12. <u-switch v-model="settings.showRecycleStatus" activeColor="#4cd964"></u-switch>
  13. </template>
  14. </u-cell>
  15. <u-cell title="是否展示库存信息" :border-bottom="true">
  16. <template #right-icon>
  17. <u-switch v-model="settings.showInventoryInfo" activeColor="#4cd964"></u-switch>
  18. </template>
  19. </u-cell>
  20. <u-cell title="是否默认展开商品详情" :border-bottom="false">
  21. <template #right-icon>
  22. <u-switch v-model="settings.expandProductDetails" activeColor="#4cd964"></u-switch>
  23. </template>
  24. </u-cell>
  25. </u-cell-group>
  26. </view>
  27. </template>
  28. <script setup>
  29. import { reactive, onMounted } from 'vue'
  30. // 设置状态
  31. const settings = reactive({
  32. showRecyclePrice: false,
  33. showRecycleStatus: false,
  34. showInventoryInfo: false,
  35. expandProductDetails: false
  36. })
  37. // 加载保存的设置
  38. function loadSettings() {
  39. try {
  40. const savedSettings = uni.getStorageSync('display_settings')
  41. if (savedSettings) {
  42. Object.assign(settings, JSON.parse(savedSettings))
  43. }
  44. } catch (error) {
  45. console.error('加载设置失败:', error)
  46. }
  47. }
  48. // 保存设置
  49. function saveSettings() {
  50. try {
  51. uni.setStorageSync('display_settings', JSON.stringify(settings))
  52. uni.showToast({
  53. title: '设置已保存',
  54. icon: 'success'
  55. })
  56. } catch (error) {
  57. console.error('保存设置失败:', error)
  58. uni.showToast({
  59. title: '保存设置失败',
  60. icon: 'error'
  61. })
  62. }
  63. }
  64. // 生命周期钩子
  65. onMounted(() => {
  66. loadSettings()
  67. })
  68. </script>
  69. <style lang="scss" scoped>
  70. .settings-container {
  71. min-height: 100vh;
  72. background-color: #f5f5f5;
  73. padding: 20rpx;
  74. .settings-group {
  75. background-color: #ffffff;
  76. border-radius: 12rpx;
  77. overflow: hidden;
  78. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  79. }
  80. }
  81. </style>