fix(非白名单拦截页): 修复图片展示逻辑,仅在白名单校验拒绝时显示图片
1个文件已修改
20 ■■■■■ 已修改文件
src/pages/not-on-whitelist/index.tsx 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/not-on-whitelist/index.tsx
@@ -1,5 +1,6 @@
import Taro, { useDidShow } from '@tarojs/taro';
import { Image, View } from '@tarojs/components';
import { useState } from 'react';
import { syncWhitelistBlockPageAccess } from '../../utils/whitelist';
import './index.less';
@@ -10,20 +11,27 @@
 * 非白名单拦截页。
 */
export default function NotOnWhitelist() {
  const [shouldRenderImage, setShouldRenderImage] = useState(false); // 白名单接口确认非白名单后才展示图片
  useDidShow(() => {
    if (typeof Taro.hideHomeButton === 'function') {
      Taro.hideHomeButton();
    }
    void syncWhitelistBlockPageAccess();
    setShouldRenderImage(false);
    void syncWhitelistBlockPageAccess().then((whitelistAccessResult) => {
      setShouldRenderImage(whitelistAccessResult === 'deny');
    });
  });
  return (
    <View className="not-on-whitelist-page">
      <Image
        className="not-on-whitelist-image"
        src={NOT_ON_WHITELIST_IMAGE_URL}
        mode="aspectFill"
      />
      {shouldRenderImage ? (
        <Image
          className="not-on-whitelist-image"
          src={NOT_ON_WHITELIST_IMAGE_URL}
          mode="aspectFill"
        />
      ) : null}
    </View>
  );
}