浏览代码

添加图片

lex 1 年之前
父节点
当前提交
ebc1440a5c

+ 32 - 16
src/components/o-sticky/index.tsx

@@ -1,6 +1,7 @@
 import { useRect } from '@vant/use'
 import { defineComponent, nextTick, PropType } from 'vue'
 import styles from './index.module.less'
+import { useResizeObserver } from '@vueuse/core'
 
 export default defineComponent({
   emits: ['getHeight'],
@@ -44,24 +45,39 @@ export default defineComponent({
       this.divStyle.bottom = this.offsetBottom || '0px'
     }
 
-    nextTick(() => {
-      // 为了处理刚开始头部高度为0的情况
-      const { height } = useRect((this as any).$refs.div)
-      this.__initHeight(height)
+    try {
+      useResizeObserver((this as any).$refs.div2, (entries: any) => {
+        const entry = entries[0]
+        const { height } = entry.contentRect
+        // console.log(height, 'height')
+        if (Math.abs(height - this.heightV) > 1) {
+          setTimeout(() => {
+            this.__initHeight(height)
+          }, 10)
+        }
+      })
+    } catch {
+      //
+    }
 
-      setTimeout(() => {
-        const { height } = useRect((this as any).$refs.div)
-        this.__initHeight(height)
-      }, 200)
+    // nextTick(() => {
+    //   // 为了处理刚开始头部高度为0的情况
+    //   const { height } = useRect((this as any).$refs.div)
+    //   this.__initHeight(height)
 
-      // 为了处理头部第一次获取高度不对的问题
-      setTimeout(() => {
-        const { height } = useRect((this as any).$refs.div2)
-        if (height !== this.heightV && this.position === 'top') {
-          this.__initHeight(height)
-        }
-      }, 1000)
-    })
+    //   setTimeout(() => {
+    //     const { height } = useRect((this as any).$refs.div)
+    //     this.__initHeight(height)
+    //   }, 200)
+
+    //   // 为了处理头部第一次获取高度不对的问题
+    //   setTimeout(() => {
+    //     const { height } = useRect((this as any).$refs.div2)
+    //     if (height !== this.heightV && this.position === 'top') {
+    //       this.__initHeight(height)
+    //     }
+    //   }, 1000)
+    // })
   },
   methods: {
     __initHeight(height: any) {

+ 30 - 1
src/school/orchestra/compontent/photo.module.less

@@ -45,6 +45,35 @@
   background: #FFF7F3;
 }
 
+
+.selectSchool {
+  height: 45px;
+
+  .icon {
+    width: 17px;
+    height: 17px;
+    margin-right: 6px;
+    flex-shrink: 0;
+  }
+
+  :global {
+    .van-cell__title {
+      overflow: hidden;
+      white-space: nowrap;
+      text-overflow: ellipsis;
+      font-size: 15px;
+      color: #333333;
+      font-weight: 500;
+    }
+
+    .van-cell__right-icon {
+      color: #333;
+      transform: rotate(90deg);
+      margin: 0 0 0 4px;
+    }
+  }
+}
+
 .btnGroup {
   display: flex;
   padding: 12px 12px 6px;
@@ -163,4 +192,4 @@
       top: 50px;
     }
   }
-}
+}

+ 43 - 36
src/school/orchestra/compontent/photo.tsx

@@ -20,7 +20,7 @@ import { defineComponent, onMounted, reactive } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
 import styles from './photo.module.less'
 import iconPhoneDefaut from '../images/icon-photo-default.png'
-import iconOrchestra from '@/views/mine-orchestra/images/icon-or.png'
+import iconOrchestra from '../images/icon-school.png'
 import OSticky from '@/components/o-sticky'
 import OHeader from '@/components/o-header'
 import { state as baseState } from '@/state'
@@ -71,9 +71,6 @@ export default defineComponent({
               name: state.photoName
             }
           })
-          // setTimeout(() => {
-          //   showToast('添加成功')
-          // }, 100)
           state.status = false
           state.photoName = null
           onSearch()
@@ -88,17 +85,10 @@ export default defineComponent({
           state.status = false
           state.photoName = null
           onSearch()
-          // setTimeout(() => {
-          //   showToast('修改成功')
-          // }, 100)
         }
         state.status = false
         state.photoName = null
         onSearch()
-        // setTimeout(() => {
-        // state.photoName = null
-        // onSearch()
-        // }, 1100)
       } catch {
         //
       }
@@ -143,28 +133,28 @@ export default defineComponent({
       }
     }
 
-    // const getSchoolList = async () => {
-    //   try {
-    //     const res = await request.post(baseState.platformApi + '/school/page', {
-    //       data: {
-    //         page: 1,
-    //         rows: 999
-    //       }
-    //     })
-    //     if (Array.isArray(res.data?.rows)) {
-    //       state.schoolList = res.data.rows.map((n: any) => {
-    //         return {
-    //           name: n.name || '',
-    //           id: n.id || ''
-    //         }
-    //       })
-    //       const tmpSchool = sessionStorage.getItem('school-photo')
-    //       state.school = tmpSchool ? JSON.parse(tmpSchool) : state.schoolList[0] || {}
-    //     }
-    //   } catch {
-    //     //
-    //   }
-    // }
+    const getSchoolList = async () => {
+      try {
+        const res = await request.post(baseState.platformApi + '/school/page', {
+          data: {
+            page: 1,
+            rows: 999
+          }
+        })
+        if (Array.isArray(res.data?.rows)) {
+          state.schoolList = res.data.rows.map((n: any) => {
+            return {
+              name: n.name || '',
+              id: n.id || ''
+            }
+          })
+          const tmpSchool = sessionStorage.getItem('school-photo')
+          state.school = tmpSchool ? JSON.parse(tmpSchool) : state.schoolList[0] || {}
+        }
+      } catch {
+        //
+      }
+    }
 
     const onDetail = (item: any) => {
       sessionStorage.setItem('orchestra-detail-tab', 'photo')
@@ -209,7 +199,9 @@ export default defineComponent({
     }
 
     onMounted(async () => {
-      // await getSchoolList()
+      if (baseState.platformType === 'TEACHER') {
+        await getSchoolList()
+      }
       await getList()
     })
     return () => (
@@ -219,6 +211,21 @@ export default defineComponent({
       >
         <OSticky position="top">
           <OHeader border={false} />
+          {baseState.platformType === 'TEACHER' && !!state.schoolList.length && (
+            <CellGroup inset style={{ marginTop: '12px' }}>
+              <Cell
+                class={styles.selectSchool}
+                center
+                isLink
+                onClick={() => (state.schoolStatus = true)}
+              >
+                {{
+                  icon: () => <img class={styles.icon} src={iconOrchestra} />,
+                  title: () => <div class="van-ellipsis">{state.school.name}</div>
+                }}
+              </Cell>
+            </CellGroup>
+          )}
           <div class={styles.btnGroup}>
             <Button
               icon="plus"
@@ -329,7 +336,7 @@ export default defineComponent({
           ]}
         />
 
-        {/* <Popup v-model:show={state.schoolStatus} position="bottom" round>
+        <Popup v-model:show={state.schoolStatus} position="bottom" round>
           <Picker
             columns={state.schoolList}
             columnsFieldNames={{ text: 'name', value: 'id' }}
@@ -346,7 +353,7 @@ export default defineComponent({
               onSearch()
             }}
           />
-        </Popup> */}
+        </Popup>
       </div>
     )
   }

二进制
src/school/orchestra/images/icon-school.png