# 空白H5 页面模板

import { useEffect, useState } from 'react';
import back from '@/assets/back.png';
import { SafeAreaType, getSafeArea, toBack } from '@/utils/hxBridge';
import cls from './index.less';

export default () => {
  const [loading, setLoading] = useState(false);
 
  const [safeArea, setSafeArea] = useState<SafeAreaType>({
    top: 0,
    left: 0,
    right: 0,
    bottom: 0,
  }); // 安全距离

  useEffect(() => {
    getSafeArea()
      ?.then((res: SafeAreaType) => {
        setSafeArea(res);
      })
      .catch((err) => {
        console.log(err, '安全区获取失败');
        // setSafeTop(null);
      });
  }, []);

  const handleBack = () => {
    toBack();
  };
 
  //加载中
  if (loading) {
    return <div className={cls.loading}>加载中...</div>;
  }

  return (
    <div className={cls.root}>
      <div className={cls.container}>
        <div
          className={cls.header}
          style={{
            paddingTop: safeArea.top,
          }}
        >
          <div className={cls.back} onClick={handleBack}>
            <img src={back} alt="" />
          </div>
          <div>个人中心</div>
          <div className={cls.right}></div>
        </div>
        <div className={cls.scrollBox}>
                 内容区域
        </div>
      </div>
    </div>
  );
};

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
49
50
51
52
53
54
55
56
57
58

.textEllipsis {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.loading {
  text-align: center;
  margin-top: 50vh;
}

.root {
  font-size: 32px;
  position: relative;
  
  .container {
    position: absolute;
    top: 0;
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;

    .header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 88px;
      padding: 0 30px;

      .back {
        width: 44px;
      }

      img {
        width: 100%;
      }

      .right {
        width: 44px;
      }
    }
    .scrollBox {
      flex: 1;
      overflow: scroll;
    }
    
  }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
49
50
51
最后更新时间: 7/2/2025, 2:56:43 PM