book-display.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.showStock" 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.showDetail" activeColor="#4cd964"></u-switch>
  23. </template>
  24. </u-cell>
  25. </u-cell-group>
  26. <u-button class="mt-40" type="primary" @click="saveSettings">保存</u-button>
  27. </view>
  28. </template>
  29. <script setup>
  30. import { reactive, onMounted } from 'vue'
  31. // 设置状态
  32. const settings = reactive({
  33. showRecyclePrice: false,
  34. showRecycleStatus: false,
  35. showStock: false,
  36. showDetail: false
  37. })
  38. // 加载保存的设置
  39. function loadSettings() {
  40. uni.$u.http.get('/app/appConf/getBookShowConfig').then(res => {
  41. if (res.code == 200) {
  42. Object.assign(settings, res.data)
  43. }
  44. })
  45. }
  46. // 保存设置
  47. function saveSettings() {
  48. uni.$u.http.post('/app/appConf/setBookShowConfig', settings).then(res => {
  49. if (res.code == 200) {
  50. uni.showToast({
  51. title: '设置已保存',
  52. icon: 'success'
  53. })
  54. } else {
  55. uni.showToast({
  56. title: '保存设置失败',
  57. icon: 'error'
  58. })
  59. }
  60. })
  61. }
  62. // 生命周期钩子
  63. onMounted(() => {
  64. loadSettings()
  65. })
  66. </script>
  67. <style lang="scss" scoped>
  68. .settings-container {
  69. min-height: 100vh;
  70. background-color: #f5f5f5;
  71. padding: 20rpx;
  72. .settings-group {
  73. background-color: #ffffff;
  74. border-radius: 12rpx;
  75. overflow: hidden;
  76. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  77. }
  78. }
  79. </style>