@@ -25,7 +25,7 @@ const UserVerifyAdmin: React.FC = () => {
const [ keywords , setKeywords ] = useState < string > ( '' )
// const [showTextArea, setShowTextArea] = useState<boolean>(false)
const [ refreshing , setRefreshing ] = useState < boolean > ( false )
const { user } = useUser ( )
const { user , fetchUserInfo } = useUser ( )
console . log ( refreshing )
// 获取状态显示
@@ -52,25 +52,66 @@ const UserVerifyAdmin: React.FC = () => {
keywords : keywords.trim ( ) ,
}
// if (Taro.getStorageSync('RoleCode') == 'zhandian') {
// @ts-ignore
// where.organizationId = Taro.getStorageSync('OrganizationId')
// }
// if (Taro.getStorageSync('RoleCode') == 'kuaidi') {
// @ts-ignore
// where.OrganizationParentId = Taro.getStorageSync('OrganizationParentId')
// }
// 如果当前登录用户可管理商户存在, 则直接按商户ID过滤
const normalizeOrganizationIds = ( value : any ) : any [ ] | undefined = > {
if ( value == null ) return undefined
if ( Array . isArray ( value ) ) return value
if ( typeof value === 'string' ) {
const trimmed = value . trim ( )
if ( ! trimmed ) return [ ]
try {
const parsed = JSON . parse ( trimmed )
if ( Array . isArray ( parsed ) ) return parsed
} catch ( _e ) { }
return trimmed
. split ( ',' )
. map ( s = > s . trim ( ) )
. filter ( Boolean )
}
return [ value ]
}
const organizations = await listOrganizations ( {
parentId : Taro.getStorageSync ( 'OrganizationId' )
} )
const organizationIds = organizations . map ( item = > item . organizationId )
// 把Taro.getStorageSync('OrganizationId')也放入数组
let merchants = user ? . merchants
if ( merchants == null ) {
const storedUser = Taro . getStorageSync ( 'User' )
if ( storedUser ) {
if ( typeof storedUser === 'string' ) {
try {
merchants = JSON . parse ( storedUser ) ? . merchants
} catch ( _e ) { }
} else {
merchants = storedUser ? . merchants
}
}
}
// 本地没有拿到 merchants 时,尝试从接口刷新一次用户信息
if ( merchants == null && user ? . userId ) {
const latestUser = await fetchUserInfo ( )
merchants = latestUser ? . merchants
}
// 查询机构列表:如果 merchants 存在,则用 organizationIds=merchants 来查
const organizationIdsParam = normalizeOrganizationIds ( merchants )
const hasMerchants = Boolean ( organizationIdsParam && organizationIdsParam . length > 0 )
const organizations = await listOrganizations (
hasMerchants
? // @ts-ignore
{ organizationIds : organizationIdsParam }
: { parentId : Taro.getStorageSync ( 'OrganizationId' ) }
)
const organizationIds = organizations . map ( item = > item . organizationId ) . filter ( Boolean ) as any [ ]
// 把 merchants/当前机构 也放入数组
if ( hasMerchants ) {
organizationIds . push ( . . . ( organizationIdsParam as any [ ] ) )
} else {
organizationIds . push ( Taro . getStorageSync ( 'OrganizationId' ) )
}
console . log ( organizationIds , 'organizationIds' )
// @ts-ignore
where . organizationIds = organizationIds ;
where . organizationIds = Array . from ( new Set ( organizationIds ) )
const res = await pageUserVerify ( where )
@@ -168,8 +209,9 @@ const UserVerifyAdmin: React.FC = () => {
}
useEffect ( ( ) = > {
if ( ! user ? . userId ) return
reload ( ) . then ( )
} , [ ] )
} , [ user ? . userId ] )
return (
< >