From 75a908e4e1844a27a3a32ee83754b831fd04198e Mon Sep 17 00:00:00 2001 From: zhangjing1 Date: Fri, 31 Jul 2026 18:17:09 +0800 Subject: [PATCH] [TBID:ECX-9542] chore: merge master changes for release --- src/api/wx.js | 12 ++ src/app.config.js | 1 + src/components/sp-search-bar/index.js | 12 +- src/subpages/auth/assets/oauth/apple.svg | 1 + src/subpages/auth/assets/oauth/facebook.svg | 4 + src/subpages/auth/assets/oauth/google.svg | 6 + src/subpages/auth/assets/oauth/line.svg | 7 + src/subpages/auth/auth-social-loading.js | 78 +++++++++++ src/subpages/auth/auth-social-loading.scss | 7 + src/subpages/auth/bindPhone.js | 5 +- src/subpages/auth/comps/comp-otherlogin.js | 130 +++++++++++++++++-- src/subpages/auth/comps/comp-otherlogin.scss | 95 ++++++++++---- src/subpages/auth/login.scss | 4 +- src/subpages/auth/util.js | 4 +- src/subpages/i18n/locales/ar.json | 6 + src/subpages/i18n/locales/en.json | 6 + src/subpages/i18n/locales/zhcn.json | 6 + src/subpages/i18n/locales/zhtw.json | 6 + src/subpages/mdugc/comps/comp-noteitem.js | 7 +- src/subpages/mdugc/index.js | 112 ++++++++-------- 20 files changed, 410 insertions(+), 99 deletions(-) create mode 100644 src/subpages/auth/assets/oauth/apple.svg create mode 100644 src/subpages/auth/assets/oauth/facebook.svg create mode 100644 src/subpages/auth/assets/oauth/google.svg create mode 100644 src/subpages/auth/assets/oauth/line.svg create mode 100644 src/subpages/auth/auth-social-loading.js create mode 100644 src/subpages/auth/auth-social-loading.scss diff --git a/src/api/wx.js b/src/api/wx.js index 283563b2b..a3bb5031e 100644 --- a/src/api/wx.js +++ b/src/api/wx.js @@ -158,6 +158,18 @@ export function getWxAuth(params) { return req.get(`/trustlogin/params`, params) } +export function getTrustLoginList(params = {}) { + return req.get('/trustlogin/list', { version_tag: 'touch', ...params }) +} + +export function socialLoginH5(params) { + return req.post('/new_login', { + ...params, + auth_type: 'social_oauth', + version_tag: 'touch' + }) +} + export function getIsNew(params) { return req.post(`/member/is_new`, params) } diff --git a/src/app.config.js b/src/app.config.js index aa0d77797..3b2d725d1 100644 --- a/src/app.config.js +++ b/src/app.config.js @@ -461,6 +461,7 @@ const config = { 'edit-password', //修改密码页面 'bindPhone', //绑定手机页面 'auth-loading', //授权加载页 + 'auth-social-loading', //第三方 OAuth 回调页 'forgotpwd', //找回密码页面 'forgotpwd-email', //邮箱找回密码(发送重置邮件) 'email-activate', //邮箱注册激活落地页 diff --git a/src/components/sp-search-bar/index.js b/src/components/sp-search-bar/index.js index 4a49bcada..6c993060e 100644 --- a/src/components/sp-search-bar/index.js +++ b/src/components/sp-search-bar/index.js @@ -74,13 +74,14 @@ export default class SpSearchBar extends Component { } handleConfirm = (e) => { - e.preventDefault && e.preventDefault() - e.stopPropagation && e.stopPropagation() - const keywords = e.detail.value.trim() + e?.preventDefault?.() + e?.stopPropagation?.() + const raw = typeof e === 'string' ? e : e?.detail?.value + const keywords = (raw == null ? '' : String(raw)).trim() if (keywords) { const value = Taro.getStorageSync(this.props.localStorageKey) let defaultValue = [] - if (value) { + if (value && typeof value === 'string') { const array = value.split(',') if (!array.includes(keywords)) { array.unshift(keywords) @@ -90,8 +91,9 @@ export default class SpSearchBar extends Component { defaultValue.push(keywords) } Taro.setStorage({ key: this.props.localStorageKey, data: defaultValue.toString() }) - this.props.onConfirm(e.detail.value) } + // 空关键词也要回调,便于清空搜索后重新拉全量列表 + this.props.onConfirm(keywords) this.setState({ showSearchDailog: false, isShowAction: false diff --git a/src/subpages/auth/assets/oauth/apple.svg b/src/subpages/auth/assets/oauth/apple.svg new file mode 100644 index 000000000..d348ca8fd --- /dev/null +++ b/src/subpages/auth/assets/oauth/apple.svg @@ -0,0 +1 @@ +Apple diff --git a/src/subpages/auth/assets/oauth/facebook.svg b/src/subpages/auth/assets/oauth/facebook.svg new file mode 100644 index 000000000..311e3d56a --- /dev/null +++ b/src/subpages/auth/assets/oauth/facebook.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/subpages/auth/assets/oauth/google.svg b/src/subpages/auth/assets/oauth/google.svg new file mode 100644 index 000000000..0406992bf --- /dev/null +++ b/src/subpages/auth/assets/oauth/google.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/subpages/auth/assets/oauth/line.svg b/src/subpages/auth/assets/oauth/line.svg new file mode 100644 index 000000000..648319087 --- /dev/null +++ b/src/subpages/auth/assets/oauth/line.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/subpages/auth/auth-social-loading.js b/src/subpages/auth/auth-social-loading.js new file mode 100644 index 000000000..21aa4ea7b --- /dev/null +++ b/src/subpages/auth/auth-social-loading.js @@ -0,0 +1,78 @@ +/** + * Copyright © ShopeX (http://www.shopex.cn). All rights reserved. + * See LICENSE file for license details. + */ +import React, { useEffect } from 'react' +import Taro, { getCurrentInstance } from '@tarojs/taro' +import { SpPage, SpLoading } from '@/components' +import { classNames } from '@/utils' +import api from '@/api' +import { useLogin } from '@/hooks' +import { useTranslation, $t } from '@/i18n' +import { setTokenAndRedirect, getToken, normalizeAuthRedirectParam } from './util' +import './auth-social-loading.scss' + +const AuthSocialLoading = () => { + const { i18n } = useTranslation() + const $instance = getCurrentInstance() || {} + + useEffect(() => { + Taro.setNavigationBarTitle({ title: $t('fd477850.88bdcf') }) + const onLang = () => Taro.setNavigationBarTitle({ title: $t('fd477850.88bdcf') }) + i18n.on('languageChanged', onLang) + return () => i18n.off('languageChanged', onLang) + }, [i18n]) + + const { + params: { code, trustlogin_tag, redi_url: rediUrlParam } + } = $instance?.router || { params: {} } + + const redi_url = + rediUrlParam || + (typeof sessionStorage !== 'undefined' + ? sessionStorage.getItem('ecx_social_oauth_redi_url') || '' + : '') + + const oauthCode = normalizeAuthRedirectParam(code) + + const { getUserInfo } = useLogin() + + const handleLogin = async () => { + const { token } = await api.wx.socialLoginH5({ + code: oauthCode, + trustlogin_tag, + auth_type: 'social_oauth' + }) + + setTokenAndRedirect(token, async () => { + await getUserInfo() + }, { rediUrl: redi_url }) + + try { + sessionStorage.removeItem('ecx_social_oauth_redi_url') + } catch (e) { + // ignore + } + } + + useEffect(() => { + const token = getToken() + if (token) { + setTokenAndRedirect(token) + return + } + if (!oauthCode || !trustlogin_tag) { + Taro.showToast({ title: $t('bf3f9cd5.26b5bd'), icon: 'none' }) + return + } + handleLogin() + }, []) + + return ( + + {$t('bf3f9cd5.26b5bd')} + + ) +} + +export default AuthSocialLoading diff --git a/src/subpages/auth/auth-social-loading.scss b/src/subpages/auth/auth-social-loading.scss new file mode 100644 index 000000000..0e78eed41 --- /dev/null +++ b/src/subpages/auth/auth-social-loading.scss @@ -0,0 +1,7 @@ +/** + * Copyright © ShopeX (http://www.shopex.cn). All rights reserved. + * See LICENSE file for license details. + */ +.page-auth-social-loading { + min-height: 100vh; +} diff --git a/src/subpages/auth/bindPhone.js b/src/subpages/auth/bindPhone.js index 2ed3b724c..2d4f9b7af 100644 --- a/src/subpages/auth/bindPhone.js +++ b/src/subpages/auth/bindPhone.js @@ -38,7 +38,7 @@ const PageBindPhone = () => { return () => i18n.off('languageChanged', onLang) }, [i18n]) const { - params: { unionid, redi_url } + params: { unionid, redi_url, user_type, trustlogin_tag } } = $instance?.router const { getUserInfo } = useLogin() @@ -96,7 +96,8 @@ const PageBindPhone = () => { username, check_type, vcode, - union_id: unionid + union_id: unionid, + user_type: user_type || trustlogin_tag || 'wechat' }) const { is_new } = tokenParseH5(token) diff --git a/src/subpages/auth/comps/comp-otherlogin.js b/src/subpages/auth/comps/comp-otherlogin.js index 6bf0ee48b..8bf48dbb0 100644 --- a/src/subpages/auth/comps/comp-otherlogin.js +++ b/src/subpages/auth/comps/comp-otherlogin.js @@ -2,43 +2,145 @@ * Copyright © ShopeX (http://www.shopex.cn). All rights reserved. * See LICENSE file for license details. */ -import React from 'react' +import React, { useEffect, useMemo, useState } from 'react' import Taro, { getCurrentInstance } from '@tarojs/taro' -import { View, Text } from '@tarojs/components' +import { View, Text, Image } from '@tarojs/components' import { isWxWeb } from '@/utils' import api from '@/api' import { useTranslation, $t } from '@/i18n' import './comp-otherlogin.scss' +import googleIcon from '../assets/oauth/google.svg' +import appleIcon from '../assets/oauth/apple.svg' +import facebookIcon from '../assets/oauth/facebook.svg' +import lineIcon from '../assets/oauth/line.svg' + +const OAUTH_ICONS = { + google: googleIcon, + apple: appleIcon, + facebook: facebookIcon, + line: lineIcon +} + +const OAUTH_LABEL_KEYS = { + google: 'e7a49201.a1b2c3', + apple: 'e7a49201.d4e5f6', + facebook: 'e7a49201.g7h8i9', + line: 'e7a49201.j0k1l2', + weixin: 'e7a49201.p6q7r8' +} + +const PROVIDER_ORDER = ['google', 'apple', 'facebook', 'line', 'weixin'] + +const isEnabled = (row) => row && (row.status === true || row.status === 'true' || row.status === 1) + +const SOCIAL_OAUTH_REDI_KEY = 'ecx_social_oauth_redi_url' + const CompOtherLogin = () => { useTranslation() - const handleClickWexin = async () => { + const [providers, setProviders] = useState([]) + + useEffect(() => { + const loadProviders = async () => { + try { + const list = await api.wx.getTrustLoginList({ version_tag: 'touch' }) + const rows = Array.isArray(list) ? list : [] + setProviders(rows.filter(isEnabled)) + } catch (e) { + setProviders([]) + } + } + loadProviders() + }, []) + + const handleClickProvider = async (row) => { const $instance = getCurrentInstance() || {} - //跳转 - const { redirect = '' } = $instance?.router?.params + const { redirect = '' } = $instance?.router?.params || {} const redirectUrl = !!redirect && redirect !== 'undefined' ? redirect : process.env.APP_HOME_PAGE - let { oauth_url = '' } = await api.wx.getWxAuth({ + + if (row.type === 'weixin') { + const { oauth_url = '' } = await api.wx.getWxAuth({ + redirect_url: redirectUrl, + trustlogin_tag: 'weixin', + version_tag: 'touch' + }) + if (oauth_url) { + window.location.replace(oauth_url) + } + return + } + + const { oauth_url = '' } = await api.wx.getWxAuth({ redirect_url: redirectUrl, - trustlogin_tag: 'weixin', + trustlogin_tag: row.type, version_tag: 'touch' }) if (oauth_url) { + try { + sessionStorage.setItem(SOCIAL_OAUTH_REDI_KEY, redirectUrl || '') + } catch (e) { + // ignore + } window.location.replace(oauth_url) } } - if (!isWxWeb) { + const visibleProviders = useMemo(() => { + const filtered = providers.filter((row) => { + if (row.type === 'weixin') { + return isWxWeb + } + return PROVIDER_ORDER.includes(row.type) + }) + return filtered.sort( + (a, b) => PROVIDER_ORDER.indexOf(a.type) - PROVIDER_ORDER.indexOf(b.type) + ) + }, [providers]) + + if (!visibleProviders.length) { return null } return ( - - {$t('8c3959b3.c4a461')} - - - - + + + + {$t('e7a49201.m3n4o5')} + + + + {visibleProviders.map((row) => { + const isWeixin = row.type === 'weixin' + const labelKey = OAUTH_LABEL_KEYS[row.type] + const label = labelKey ? $t(labelKey) : row.name || row.type + + return ( + handleClickProvider(row)} + > + + {isWeixin ? ( + + ) : ( + + )} + + {label} + + ) + })} ) diff --git a/src/subpages/auth/comps/comp-otherlogin.scss b/src/subpages/auth/comps/comp-otherlogin.scss index 1448d44ed..903ebeb73 100644 --- a/src/subpages/auth/comps/comp-otherlogin.scss +++ b/src/subpages/auth/comps/comp-otherlogin.scss @@ -3,33 +3,82 @@ * See LICENSE file for license details. */ .comp-other-login { - position: relative; - border-top: 1px solid rgba(0, 0, 0, 0.1); - margin-top: 10px; - .text { - color: rgba(197, 202, 213, 1); - font-size: 26px; - position: relative; - margin: -18px auto 0; - background-color: white; - width: 200px; + width: 100%; + padding: 0; + box-sizing: border-box; + + .oauth-divider { + display: flex; + align-items: center; + gap: 24px; + margin: 48px 0 32px; + + &__line { + flex: 1; + height: 1px; + background: #e2e4ea; + } + + &__text { + flex-shrink: 0; + font-size: 26px; + line-height: 1; + color: #858b9c; + } } - .loginway { - padding: 24px 0 10px 0; - @include flex-center(); - .wechat { - width: 90px; - height: 90px; - border: 1px solid #c5cad5; - border-radius: 50%; - color: rgba(0, 200, 0, 1); + .oauth-buttons { + display: flex; + flex-direction: column; + gap: 20px; + width: 100%; + } - @include flex-center(); + .oauth-button { + position: relative; + display: flex; + align-items: center; + justify-content: center; + width: 100%; + min-height: 96px; + padding: 0 32px; + border: 1px solid #111a34; + border-radius: 4px; + background: #fff; + box-sizing: border-box; - .icon-weixin { - font-size: 40px; - } + &__icon-wrap { + position: absolute; + left: 32px; + top: 50%; + transform: translateY(-50%); + width: 40px; + height: 40px; + display: flex; + align-items: center; + justify-content: center; + } + + &__icon { + width: 32px; + height: 32px; + } + + &__wechat-icon { + font-size: 40px; + color: #00c800; + line-height: 1; + } + + &__label { + font-size: 28px; + line-height: 1.3; + color: #111a34; + text-align: center; + } + + &--weixin .oauth-button__label { + padding-left: 0; } } } diff --git a/src/subpages/auth/login.scss b/src/subpages/auth/login.scss index 4ae601f9a..7a0026f05 100644 --- a/src/subpages/auth/login.scss +++ b/src/subpages/auth/login.scss @@ -195,11 +195,13 @@ $border-color: #e2e4ea; } } .other-login { - margin-top: 100px; + margin-top: 48px; left: 0; right: 0; bottom: 0; text-align: center; + width: 100%; + box-sizing: border-box; } } diff --git a/src/subpages/auth/util.js b/src/subpages/auth/util.js index 386e01eb5..631b12cc9 100644 --- a/src/subpages/auth/util.js +++ b/src/subpages/auth/util.js @@ -53,7 +53,7 @@ function getRedirectUrl() {} // options.forceMemberCenter:注册成功等场景固定进会员中心,忽略 redi_url / redirect async function setTokenAndRedirect(token = '', tokenSetSuccessCallback, options) { const opts = typeof options === 'object' && options !== null ? options : {} - const { forceMemberCenter = false } = opts + const { forceMemberCenter = false, rediUrl: optsRediUrl } = opts const hasToken = setToken(token) @@ -64,6 +64,8 @@ async function setTokenAndRedirect(token = '', tokenSetSuccessCallback, options) const { redi_url, redirect } = router?.params || {} const url = forceMemberCenter ? '/subpages/member/index' + : optsRediUrl + ? normalizeAuthRedirectParam(optsRediUrl) : redi_url ? normalizeAuthRedirectParam(redi_url) : redirect diff --git a/src/subpages/i18n/locales/ar.json b/src/subpages/i18n/locales/ar.json index 7885d9a96..f927eaa91 100644 --- a/src/subpages/i18n/locales/ar.json +++ b/src/subpages/i18n/locales/ar.json @@ -1556,6 +1556,12 @@ "bf3f9cd5.26b5bd": "جارٍ التحميل...", "fd477850.88bdcf": "جارٍ تسجيل الدخول...", "8c3959b3.c4a461": "طرق تسجيل الدخول الأخرى", + "e7a49201.m3n4o5": "أو", + "e7a49201.a1b2c3": "تسجيل الدخول بحساب Google", + "e7a49201.d4e5f6": "تسجيل الدخول باستخدام Apple ID", + "e7a49201.g7h8i9": "تسجيل الدخول بحساب Facebook", + "e7a49201.j0k1l2": "تسجيل الدخول باستخدام LINE", + "e7a49201.p6q7r8": "تسجيل الدخول باستخدام WeChat", "24f4b47f.c4d0c8": "يجب أن تتكون كلمة المرور من 6–16 رقمًا أو حرفًا", "70e510e9.787a47": "يرجى إدخال رقم جوالك", "70e510e9.1fb0b4": "رقم الجوال هذا غير مسجل", diff --git a/src/subpages/i18n/locales/en.json b/src/subpages/i18n/locales/en.json index 4f52e09e9..1260faab0 100644 --- a/src/subpages/i18n/locales/en.json +++ b/src/subpages/i18n/locales/en.json @@ -1556,6 +1556,12 @@ "bf3f9cd5.26b5bd": "Loading...", "fd477850.88bdcf": "Logging in...", "8c3959b3.c4a461": "Other sign-in methods", + "e7a49201.m3n4o5": "Or", + "e7a49201.a1b2c3": "Log in with Google", + "e7a49201.d4e5f6": "Log in with Apple ID", + "e7a49201.g7h8i9": "Log in with Facebook", + "e7a49201.j0k1l2": "Log in with LINE", + "e7a49201.p6q7r8": "Log in with WeChat", "24f4b47f.c4d0c8": "Password must be 6–16 digits or letters", "70e510e9.787a47": "Please enter your mobile number", "70e510e9.1fb0b4": "This mobile number is not registered", diff --git a/src/subpages/i18n/locales/zhcn.json b/src/subpages/i18n/locales/zhcn.json index 42316d0bf..6a28d24ac 100644 --- a/src/subpages/i18n/locales/zhcn.json +++ b/src/subpages/i18n/locales/zhcn.json @@ -1560,6 +1560,12 @@ "bf3f9cd5.26b5bd": "加载中...", "fd477850.88bdcf": "登陆中...", "8c3959b3.c4a461": "其它方式登录", + "e7a49201.m3n4o5": "或", + "e7a49201.a1b2c3": "使用 Google 帐户登录", + "e7a49201.d4e5f6": "用 Apple ID 登录", + "e7a49201.g7h8i9": "用 Facebook 帐户登录", + "e7a49201.j0k1l2": "用 LINE 登录", + "e7a49201.p6q7r8": "使用微信登录", "24f4b47f.c4d0c8": "密码需由6-16位数字或字母组成", "70e510e9.787a47": "请输入您的手机号码", "70e510e9.1fb0b4": "该手机号码未注册", diff --git a/src/subpages/i18n/locales/zhtw.json b/src/subpages/i18n/locales/zhtw.json index 0bf903ef6..e2281a151 100644 --- a/src/subpages/i18n/locales/zhtw.json +++ b/src/subpages/i18n/locales/zhtw.json @@ -1559,6 +1559,12 @@ "bf3f9cd5.26b5bd": "加載中...", "fd477850.88bdcf": "登陸中...", "8c3959b3.c4a461": "其它方式登錄", + "e7a49201.m3n4o5": "或", + "e7a49201.a1b2c3": "使用 Google 帳戶登入", + "e7a49201.d4e5f6": "用 Apple ID 登入", + "e7a49201.g7h8i9": "用 Facebook 帳戶登入", + "e7a49201.j0k1l2": "用 LINE 登入", + "e7a49201.p6q7r8": "使用微信登入", "24f4b47f.c4d0c8": "密碼需由6-16位數字或字母組成", "70e510e9.787a47": "請輸入您的手機號碼", "70e510e9.1fb0b4": "該手機號碼未註冊", diff --git a/src/subpages/mdugc/comps/comp-noteitem.js b/src/subpages/mdugc/comps/comp-noteitem.js index 4dc7ab4fd..b62879be5 100644 --- a/src/subpages/mdugc/comps/comp-noteitem.js +++ b/src/subpages/mdugc/comps/comp-noteitem.js @@ -28,12 +28,17 @@ function CompNoteItem(props) { const { userInfo = {} } = useSelector((state) => state.user) useEffect(() => { + if (!info) return setState((draft) => { draft.likes = info.likes draft.likeStatus = info.likeStatus }) }, [info]) + if (!info) { + return null + } + const handleClick = () => { const { postId, status } = info if (status != '4') { @@ -62,7 +67,7 @@ function CompNoteItem(props) { return ( - {info.badges.map((item, index) => ( + {(info?.badges || []).map((item, index) => ( {item.badge_name} diff --git a/src/subpages/mdugc/index.js b/src/subpages/mdugc/index.js index 803a494b6..7ed37e245 100644 --- a/src/subpages/mdugc/index.js +++ b/src/subpages/mdugc/index.js @@ -26,6 +26,7 @@ function UgcIndex() { ) const initialState = { keyword: '', + searchKeyword: '', tagsList: [], curTagIndex: 0, curFilterIndex: 0, @@ -34,8 +35,11 @@ function UgcIndex() { footerHeight: 0 } const [state, setState] = useImmer(initialState) - const { keyword, tagsList, curTagIndex, curFilterIndex, leftList, rightList } = state + const { keyword, searchKeyword, tagsList, curTagIndex, curFilterIndex, leftList, rightList } = + state const listRef = useRef() + const searchKeywordRef = useRef('') + searchKeywordRef.current = searchKeyword useEffect(() => { Taro.setNavigationBarTitle({ title: $t('d668d0e3.888af1') }) @@ -57,9 +61,9 @@ function UgcIndex() { useEffect(() => { if (tagsList.length > 0) { - listRef.current.reset() + listRef.current?.reset() } - }, [curTagIndex, keyword, curFilterIndex, tagsList]) + }, [curTagIndex, curFilterIndex, tagsList, searchKeyword]) // useEffect(() => { // getUgcList() @@ -88,66 +92,70 @@ function UgcIndex() { // 列表 const fetch = async ({ pageIndex, pageSize }) => { Taro.showLoading() - let params = { - page: pageIndex, - pageSize, - sort: curFilterIndex == 0 ? 'likes desc' : 'created desc', - content: keyword + try { + let params = { + page: pageIndex, + pageSize, + sort: curFilterIndex == 0 ? 'likes desc' : 'created desc' + } + const keyword = (searchKeywordRef.current || '').trim() + if (keyword) { + params.content = keyword + } + + if (tagsList.length > 0 && tagsList[curTagIndex]) { + params = { + ...params, + topics: [tagsList[curTagIndex].tag_id] + } + } + + const res = (await mdugcApi.postlist(params)) || {} + const list = Array.isArray(res.list) ? res.list : [] + const total = res.total_count + + let nList = pickBy(list, mdugcDoc.UGC_LIST) + + const resLeftList = nList.filter((item, index) => index % 2 == 0) + const resRightList = nList.filter((item, index) => index % 2 == 1) + + setState((draft) => { + if (pageIndex === 1) { + draft.leftList = [resLeftList] + draft.rightList = [resRightList] + } else { + draft.leftList[pageIndex - 1] = resLeftList + draft.rightList[pageIndex - 1] = resRightList + } + }) + + return { total: total || 0 } + } finally { + Taro.hideLoading() } - - if (tagsList.length > 0) { - params = { - ...params, - topics: [tagsList[curTagIndex].tag_id] - } - } - - const { list, total_count: total } = await mdugcApi.postlist(params) - - let nList = pickBy(list, mdugcDoc.UGC_LIST) - - const resLeftList = nList.filter((item, index) => { - if (index % 2 == 0) { - return item - } - }) - const resRightList = nList.filter((item, index) => { - if (index % 2 == 1) { - return item - } - }) - - setState((draft) => { - draft.leftList[pageIndex - 1] = resLeftList - draft.rightList[pageIndex - 1] = resRightList - }) - Taro.hideLoading() - - return { total: total || 0 } } - const handleOnClear = async () => { - await setState((draft) => { - draft.keyword = '' + const refreshBySearch = (val = '') => { + const nextKeyword = typeof val === 'string' ? val : '' + searchKeywordRef.current = nextKeyword + setState((draft) => { + draft.keyword = nextKeyword + draft.searchKeyword = nextKeyword draft.leftList = [] draft.rightList = [] }) } + const handleOnClear = () => { + refreshBySearch('') + } + const handleSearchCancel = () => { - setState((draft) => { - draft.keyword = '' - draft.leftList = [] - draft.rightList = [] - }) + refreshBySearch('') } - const handleConfirm = async (val) => { - setState((draft) => { - draft.keyword = val - draft.leftList = [] - draft.rightList = [] - }) + const handleConfirm = (val) => { + refreshBySearch(val) } const onChangeTag = (index, item) => {