Blame view

美国版/Food Labeling Management App UniApp/src/components/SideMenu.vue 8.05 KB
b165f94a   “wangming”   111
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  <template>
    <view v-if="isShown" class="drawer-mask" @click="close">
      <view class="drawer-panel" :class="animClass" :style="{ paddingTop: statusBarHeight + 'px' }" @click.stop>
        <view class="drawer-top">
          <view class="user-row">
            <view class="avatar-circle">
              <AppIcon name="user" size="sm" color="white" />
            </view>
            <view class="user-texts">
              <text class="user-name">{{ userName }}</text>
              <text class="store-label">{{ storeName }}</text>
            </view>
          </view>
        </view>
  
        <view class="drawer-menu">
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
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
          <template v-for="item in items" :key="item.key">
            <!-- 有子菜单的项 -->
            <view v-if="item.children" class="menu-group">
              <view
                class="menu-item menu-item-parent"
                :class="{ expanded: expandedKey === item.key }"
                @click="toggleExpand(item.key)"
              >
                <view class="menu-icon">
                  <AppIcon :name="item.icon" size="md" color="gray" />
                </view>
                <text class="menu-label">{{ t(item.labelKey) }}</text>
                <view class="menu-chevron">
                  <AppIcon
                    :name="expandedKey === item.key ? 'chevronUp' : 'chevronDown'"
                    size="sm"
                    color="gray"
                  />
                </view>
              </view>
              <view v-show="expandedKey === item.key" class="menu-children">
                <view
                  v-for="child in item.children"
                  :key="child.path"
                  class="menu-item child"
                  :class="{ active: isActive(child.path) }"
                  @click="handleItemClick(child)"
                >
                  <view class="menu-icon" />
                  <text class="menu-label">{{ t(child.labelKey) }}</text>
                </view>
              </view>
b165f94a   “wangming”   111
49
            </view>
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
            <!-- 普通菜单项 -->
            <view
              v-else
              class="menu-item"
              :class="{ active: isActive(item.path), danger: item.danger }"
              @click="handleItemClick(item)"
            >
              <view class="menu-icon">
                <AppIcon
                  :name="item.icon"
                  size="md"
                  :color="isActive(item.path) || item.danger ? 'white' : 'gray'"
                />
              </view>
              <text class="menu-label">{{ t(item.labelKey) }}</text>
            </view>
          </template>
b165f94a   “wangming”   111
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        </view>
  
        <view class="drawer-footer" :style="{ paddingBottom: (bottomSafeArea + 24) + 'px' }">
          <image class="footer-logo-img" src="/static/logo_us.png" mode="aspectFit" />
        </view>
      </view>
    </view>
  </template>
  
  <script setup lang="ts">
  import { computed, ref, watch, nextTick } from 'vue'
  import { useI18n } from 'vue-i18n'
  import AppIcon from './AppIcon.vue'
  import { getStatusBarHeight, getBottomSafeArea } from '../utils/statusBar'
6faaf539   杨鑫   APP 登录门店对接
81
  import { clearAuthSession } from '../utils/authSession'
b165f94a   “wangming”   111
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
  
  const props = defineProps<{
    modelValue: boolean
  }>()
  
  const emit = defineEmits<{
    (e: 'update:modelValue', value: boolean): void
  }>()
  
  const { t } = useI18n()
  const statusBarHeight = getStatusBarHeight()
  const bottomSafeArea = getBottomSafeArea()
  
  const isShown = ref(false)
  const animClass = ref('')
  
  const userName = computed(() => {
    const stored = uni.getStorageSync('userName')
    return stored || 'John Smith'
  })
  
  const storeName = computed(() => {
    const stored = uni.getStorageSync('storeName')
    return stored || 'MedVantage'
  })
  
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
108
109
  const expandedKey = ref<string | null>(null)
  
b165f94a   “wangming”   111
110
  const items = [
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
111
112
113
    { key: 'home', path: '/pages/index/index', icon: 'home', labelKey: 'Home' },
    { key: 'Labeling', path: '/pages/labels/labels', icon: 'tag', labelKey: 'Labeling' },
    {
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
114
115
116
117
118
119
120
121
      key: 'report',
      icon: 'fileText',
      labelKey: 'more.report',
      children: [
        { path: '/pages/more/print-log', labelKey: 'more.printLog' },
        { path: '/pages/more/label-report', labelKey: 'more.labelReport' },
      ],
    },
b165f94a   “wangming”   111
122
123
124
    { key: 'profile', path: '/pages/more/profile', icon: 'user', labelKey: 'more.profile' },
    { key: 'location', path: '/pages/more/location', icon: 'mapPin', labelKey: 'more.location' },
    { key: 'sync', path: '/pages/more/sync', icon: 'refresh', labelKey: 'more.sync' },
b165f94a   “wangming”   111
125
126
127
128
    { key: 'support', path: '/pages/more/support', icon: 'help', labelKey: 'more.support' },
    { key: 'logout', path: '__logout__', icon: 'logout', labelKey: 'more.logout', danger: true },
  ]
  
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
129
130
131
132
  const toggleExpand = (key: string) => {
    expandedKey.value = expandedKey.value === key ? null : key
  }
  
b165f94a   “wangming”   111
133
134
135
136
137
  watch(
    () => props.modelValue,
    (val) => {
      if (val) {
        isShown.value = true
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
138
139
140
        if (currentPath.value.startsWith('/pages/more/print-log') || currentPath.value.startsWith('/pages/more/label-report')) {
          expandedKey.value = 'report'
        }
b165f94a   “wangming”   111
141
142
143
144
        nextTick(() => {
          animClass.value = 'opening'
        })
      } else if (isShown.value) {
b165f94a   “wangming”   111
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
        animClass.value = 'closing'
        setTimeout(() => {
          isShown.value = false
          animClass.value = ''
        }, 220)
      }
    },
    { immediate: true }
  )
  
  const close = () => {
    emit('update:modelValue', false)
  }
  
  const currentPath = computed(() => {
    const pages = getCurrentPages()
    const cur = pages[pages.length - 1] as any
    const route = (cur && cur.route) ? '/' + cur.route : ''
    return route
  })
  
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
166
  const isActive = (path: string) => !!path && path !== '__logout__' && currentPath.value === path
b165f94a   “wangming”   111
167
168
  
  const handleLogout = () => {
6faaf539   杨鑫   APP 登录门店对接
169
    clearAuthSession()
b165f94a   “wangming”   111
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
    uni.redirectTo({ url: '/pages/login/login' })
  }
  
  const handleItemClick = (item: any) => {
    if (item.isDivider) return
    emit('update:modelValue', false)
    if (item.path === '__logout__') {
      handleLogout()
      return
    }
    if (item.path && currentPath.value !== item.path) {
      uni.redirectTo({ url: item.path })
    }
  }
  </script>
  
  <style scoped>
  .drawer-mask {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    justify-content: flex-start;
    align-items: stretch;
  }
  
  .drawer-panel {
    width: 76%;
    max-width: 640rpx;
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
203
    background: #1F3A8A;
b165f94a   “wangming”   111
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
    padding: 16rpx 32rpx 0;
    box-shadow: 4rpx 0 32rpx rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
  }
  
  .drawer-panel.opening {
    animation: slide-in-left 220ms ease-out forwards;
  }
  
  .drawer-panel.closing {
    animation: slide-out-left 220ms ease-in forwards;
  }
  
  @keyframes slide-in-left {
    from {
      transform: translateX(-100%);
    }
    to {
      transform: translateX(0);
    }
  }
  
  @keyframes slide-out-left {
    from {
      transform: translateX(0);
    }
    to {
      transform: translateX(-100%);
    }
  }
  
  .drawer-top {
    padding-bottom: 32rpx;
    border-bottom: 1rpx solid rgba(148, 163, 184, 0.2);
  }
  
  .avatar-circle {
    width: 64rpx;
    height: 64rpx;
    border-radius: 50%;
    background: var(--theme-primary);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .user-row {
    display: flex;
    align-items: center;
    gap: 16rpx;
  }
  
  .user-texts {
    flex: 1;
    min-width: 0;
  }
  
  .user-name {
    font-size: 30rpx;
    font-weight: 600;
    color: #ffffff;
    display: block;
    margin-bottom: 4rpx;
  }
  
  .store-label {
    font-size: 24rpx;
    color: #9ca3af;
    display: block;
  }
  
  .drawer-menu {
    margin-top: 24rpx;
    flex: 1;
  }
  
  .menu-item {
    padding: 18rpx 12rpx;
    display: flex;
    align-items: center;
    gap: 20rpx;
    border-radius: 12rpx;
  }
  
  .menu-icon {
    width: 56rpx;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .menu-label {
    font-size: 30rpx;
    color: #e5e7eb;
  }
  
  .menu-item.active {
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
304
    background: #1447E6;
b165f94a   “wangming”   111
305
306
307
308
309
310
  }
  
  .menu-item.active .menu-label {
    color: #ffffff;
  }
  
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
  .menu-group {
    margin-bottom: 4rpx;
  }
  
  .menu-chevron {
    margin-left: auto;
  }
  
  .menu-children {
    padding-left: 76rpx;
    padding-bottom: 8rpx;
  }
  
  .menu-item.child {
    padding: 12rpx 12rpx;
  }
  
  .menu-item.child .menu-icon {
    width: 0;
    min-width: 0;
  }
  
b165f94a   “wangming”   111
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
  .drawer-footer {
    padding: 24rpx 0 48rpx;
    border-top: 1rpx solid rgba(148, 163, 184, 0.2);
    flex-shrink: 0;
  }
  
  .footer-logo-img {
    width: 260rpx;
    height: 72rpx;
    opacity: 0.85;
    background: rgba(255,255,255,0.92);
    border-radius: 10rpx;
    padding: 8rpx 12rpx;
  }
  </style>