- 做了下订单时选择地址后返回的效果,但没有选择的时候点击地址也返回了,怎么让它分情况确定返不返回?
问题一: [图片][图片] 怎么让用户在正常进入时点击地址不会返回,而在订单页面跳转选择时,点击地址返回? 部分代码如下: [图片][图片][图片] 问题二: [图片][图片] 有些时候,点进添加或编辑地址页面再退出到主页,从主页退到首页时,主页也会跳出未保存提醒(主页没有设置),这是为什么?怎么解决? [图片]
2022-12-07 - 如何通过导航条对列表数据进行分类?
如下图:需要根据点击的导航标题,显示出相应的列表数据在页面中。 [图片] 目前的导航条与列表数据没有连通,点击无法切换数据。 应该怎么把列表中的数据区分开?怎么连在导航条中呢? 主页代码: [图片][图片][图片][图片][图片] 尝试过用Swiper来写,但是可能是接口中的列表数据没有区分出来,效果没有实现。 [图片][图片]
2022-12-06 - 如何改变自定义列表组件中某一条数据的样式?
[图片][图片] 第一图为最终呈现效果图,第二图为当前实现效果。 部分代码: [图片][图片] 如何实现最终效果?
2022-12-02 - 如何区分组件中不同的点击事件?
一个自定义列表组件里,有三个按钮,第一个点击切换页面(可正常实现),第二个点击弹出确认弹窗,第三个点击弹出数据弹窗。 目前在点击第二个按钮或第三个按钮时,页面会同时弹出两个弹窗,应该怎么把这两个按钮的点击事件区分开? 当前效果截图: [图片][图片] 需求:需要在点击“确认收货”时弹出提示弹窗,点击“联系商家”时弹出商家信息弹窗。 部分代码截图: [图片][图片] [图片]
2022-12-02 - 如何自动刷新页面中的组件数据?
需要实现的效果:点击页面顶部的标题,页面中的组件自动刷新并展示标题的相应内容。 但目前组件无法自动刷新,需要手动进行刷新两次以上,列表才会呈现出对应的数据。如何实现自动刷新? 页面截图: [图片] 代码截图: [图片][图片][图片][图片][图片]
2022-11-25 - 帖子发表成功,但一直显示“内容审核中,请稍后加载重试”是为什么?
[图片]
2022-11-25 - 如何自动刷新组件数据?点击页面顶部标题栏,下方组件列表自动刷新数据,如何实现?
需要实现效果:点击页面顶部的标题,页面中自动刷新列表并展示相关数据。 当前效果:页面正常展示,接口数据正常连接,但点击后不能自动刷新,只能手动刷新两次,列表数据才符合所点击标题。 截图: [图片] 当前页面代码(index.js): import React, { useEffect, memo, useState, useCallback, useMemo } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { View, Text, Image, navigateTo, ScrollView, showLoading, hideLoading, createSelectorQuery, showModal, } from 'remax/wechat'; import { connect } from 'react-redux'; import { Popup } from 'annar'; import Nav from '@/components/nav'; import request from '@/utils/request'; import useSysInfo from '../../../hooks/sysInfo' import useBackEvent from '@/hooks/navEvent' import styles from './index.css'; import { getSysConf } from '../../../actions/common'; import HelpItem from '../../../components/helpItem'; import { usePageEvent } from '@remax/macro'; const HelptitleItem = memo(function HelptitleItem(props) { const { tab: { id, name }, current, callback } = props; const Cls = classnames(styles.question, { [styles.selectquestion]: id === current }) return ( <View className={styles.list}> <View id={'tab_' + id} className={Cls} onTap={() => { callback(id) console.log("HelptitleItem id:", id) }} > <Text>{name}</Text> {id === current ? <View className={styles.greenline}></View> : null} </View> </View> ) }) HelptitleItem.propTypes = { tab: PropTypes.object.isRequired, callback: PropTypes.func.isRequired } const Help = function (props) { const [toView, setToView] = useState('') const [tabs, setTabs] = useState(); const { currentTab } = props; const [refreshTriggered, setRefreshTriggered] = useState(false); const [isLoading, setIsLoading] = useState(false); const { getSysConf, sysConf, userInfo } = props; const sysInfo = useSysInfo(); const [hasData, setHasData] = useState(true); const [List, setList] = useState(); useEffect(() => { getSysConf() }, []) const { homeAction, backAction } = useBackEvent(currentTab); const [page, setPage] = useState(1); const [Id, setId] = useState(34); const loadTabs = useCallback(() => { return request({ url: '/getCatalogList', method: 'get', data: { type: 1 }, // cacheKey: tabs, }) }, []) const loadList = useCallback((passPage) => { return request({ url: '/getArticleList', data: { // page: passPage ? passPage : page, // class_id: currentClassId, type: 1, catalog_id: Id }, }) }, [Id, page]) const loadMore = useCallback(() => { if (hasData) { loadList().then(moreData => { setList(preList => preList.concat(moreData)) setPage(prev => prev + 1); if (moreData.length < 10) { setHasData(false); } }) } else { showToast({ title: '没有更多了~', icon: 'none' }) } }, [Id, page, hasData]) function showModal(data) { wx.setStorageSync('title', data.title) } const init = useCallback(async () => { if (isLoading) return; const page = 1; setPage(page); setHasData(true); setIsLoading(true); const List = await loadList(page); setIsLoading(false); setPage(prevPage => prevPage + 1); setList(List); setRefreshTriggered(false) if ( List.length < 10) { setHasData(false); } }, [isLoading, page]); useEffect(() => { init(); }, []) useEffect(() => { if (isLoading) { showLoading({ title: '加载中', mask: true }) } else { hideLoading() } }, [isLoading]) const changeClassId = useCallback((id) => { let index = tabs.findIndex(e => e.id === id); console.log(index, tabs) let scrollId = tabs[index - 2] ? tabs[index - 2].id : id; setToView('tab_' + scrollId) setId(id) }, [tabs]) useEffect(() => { setIsLoading(true) loadTabs().then(res => { setIsLoading(false) setTabs(res) setId(res[0].id); }).catch(e => { setIsLoading(false) }) }, []) useEffect(() => { if (tabs) { const query = createSelectorQuery() query.select('#nav').boundingClientRect() query.exec(res => { // setNavHeight(res[0].height) }) } }, [tabs]) usePageEvent('onShareAppMessage', () => { return { path: 'packagePagesE/help/index/index', } }) if (!tabs) return null; return ( sysConf && <View className={styles.personal} onTap={() => { loadList() }} style={{ height: sysInfo.safeArea.bottom + 'PX' }}> <Nav title="帮助中心" goIndex={homeAction} onBack={backAction} showLeftFunc={true} /> <View className={styles.tabs} > <ScrollView className={styles.top} scrollX enableFlex scrollIntoView={toView} enhanced={true} show-scrollbar={false} > { tabs.map(v => { return ( <HelptitleItem tab={v} key={v.Id} current={Id} callback={changeClassId} /> ) }) } </ScrollView> </View> { (List && List.length > 0) ? <ScrollView className={styles.title} scrollY refresherEnabled refresherTriggered={refreshTriggered} lowerThreshold={60} bindscrolltolower={loadMore} bindrefresherrefresh={() => { init(); setRefreshTriggered(true) }}> { List.map((v, i) => { return ( <HelpItem key={i} {...v} showModal={() => { showModal(v) }} /> ) }) } </ScrollView> : null } </View > ) } const mapStateToProps = (state) => { const { sysConf, userInfo } = state.common; return { sysConf, userInfo } } const mapDispatchToProps = (dispatch) => { return { getSysConf: (conf) => { dispatch(getSysConf(conf)) } } } export default connect(mapStateToProps, mapDispatchToProps)(Help)
2022-11-25 - 怎么让组件数据自动更新?点击页面顶部导航,更新组件数据,如何实现?
问题:怎么让组件数据自动更新? 需要实现效果:点击页面顶部标题栏,下方的组件列表刷新相关数据。 目前效果:点击顶部栏样式正常实现,接口正常连接且成功,但下方组件列表没有同步刷新,需要手动刷新两次才能正确实现效果。 当前效果截图: [图片] 当前页面代码(index.js): import React, { useEffect, memo, useState, useCallback, useMemo } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { View, Text, Image, navigateTo, ScrollView, showLoading, hideLoading, createSelectorQuery, showModal, } from 'remax/wechat'; import { connect } from 'react-redux'; import { Popup } from 'annar'; import Nav from '@/components/nav'; import request from '@/utils/request'; import useSysInfo from '../../../hooks/sysInfo' import useBackEvent from '@/hooks/navEvent' import styles from './index.css'; import { getSysConf } from '../../../actions/common'; import HelpItem from '../../../components/helpItem'; import { usePageEvent } from '@remax/macro'; const HelptitleItem = memo(function HelptitleItem(props) { const { tab: { id, name }, current, callback } = props; const Cls = classnames(styles.question, { [styles.selectquestion]: id === current }) return ( <View className={styles.list}> <View id={'tab_' + id} className={Cls} onTap={() => { callback(id) console.log("HelptitleItem id:", id) }} > <Text>{name}</Text> {id === current ? <View className={styles.greenline}></View> : null} </View> </View> ) }) HelptitleItem.propTypes = { tab: PropTypes.object.isRequired, callback: PropTypes.func.isRequired } const Help = function (props) { const [toView, setToView] = useState('') const [tabs, setTabs] = useState(); const { currentTab } = props; const [refreshTriggered, setRefreshTriggered] = useState(false); const [isLoading, setIsLoading] = useState(false); const { getSysConf, sysConf, userInfo } = props; const sysInfo = useSysInfo(); const [hasData, setHasData] = useState(true); const [List, setList] = useState(); useEffect(() => { getSysConf() }, []) const { homeAction, backAction } = useBackEvent(currentTab); const [page, setPage] = useState(1); const [Id, setId] = useState(34); const loadTabs = useCallback(() => { return request({ url: '/getCatalogList', method: 'get', data: { type: 1 }, // cacheKey: tabs, }) }, []) const loadList = useCallback((passPage) => { return request({ url: '/getArticleList', data: { // page: passPage ? passPage : page, // class_id: currentClassId, type: 1, catalog_id: Id }, }) }, [Id, page]) const loadMore = useCallback(() => { if (hasData) { loadList().then(moreData => { setList(preList => preList.concat(moreData)) setPage(prev => prev + 1); if (moreData.length < 10) { setHasData(false); } }) } else { showToast({ title: '没有更多了~', icon: 'none' }) } }, [Id, page, hasData]) function showModal(data) { wx.setStorageSync('title', data.title) } const init = useCallback(async () => { if (isLoading) return; const page = 1; setPage(page); setHasData(true); setIsLoading(true); const List = await loadList(page); setIsLoading(false); setPage(prevPage => prevPage + 1); setList(List); setRefreshTriggered(false) if ( List.length < 10) { setHasData(false); } }, [isLoading, page]); useEffect(() => { init(); }, []) useEffect(() => { if (isLoading) { showLoading({ title: '加载中', mask: true }) } else { hideLoading() } }, [isLoading]) const changeClassId = useCallback((id) => { let index = tabs.findIndex(e => e.id === id); console.log(index, tabs) let scrollId = tabs[index - 2] ? tabs[index - 2].id : id; setToView('tab_' + scrollId) setId(id) }, [tabs]) useEffect(() => { setIsLoading(true) loadTabs().then(res => { setIsLoading(false) setTabs(res) setId(res[0].id); }).catch(e => { setIsLoading(false) }) }, []) useEffect(() => { if (tabs) { const query = createSelectorQuery() query.select('#nav').boundingClientRect() query.exec(res => { // setNavHeight(res[0].height) }) } }, [tabs]) usePageEvent('onShareAppMessage', () => { return { path: 'packagePagesE/help/index/index', } }) if (!tabs) return null; return ( sysConf && <View className={styles.personal} onTap={() => { loadList() }} style={{ height: sysInfo.safeArea.bottom + 'PX' }}> <Nav title="帮助中心" goIndex={homeAction} onBack={backAction} showLeftFunc={true} /> <View className={styles.tabs} > <ScrollView className={styles.top} scrollX enableFlex scrollIntoView={toView} enhanced={true} show-scrollbar={false} > { tabs.map(v => { return ( <HelptitleItem tab={v} key={v.Id} current={Id} callback={changeClassId} /> ) }) } </ScrollView> </View> { (List && List.length > 0) ? <ScrollView className={styles.title} scrollY refresherEnabled refresherTriggered={refreshTriggered} lowerThreshold={60} bindscrolltolower={loadMore} bindrefresherrefresh={() => { init(); setRefreshTriggered(true) }}> { List.map((v, i) => { return ( <HelpItem key={i} {...v} showModal={() => { showModal(v) }} /> ) }) } </ScrollView> : null } </View > ) } const mapStateToProps = (state) => { const { sysConf, userInfo } = state.common; return { sysConf, userInfo } } const mapDispatchToProps = (dispatch) => { return { getSysConf: (conf) => { dispatch(getSysConf(conf)) } } } export default connect(mapStateToProps, mapDispatchToProps)(Help)
2022-11-25 - 自定义组件内,怎么让它点击时切换样式?
一个自定义列表组件,需呈现效果: 1.点击时字体放大,底部出现绿条; 2.未点击时标准字体大小,底部没有绿条; 3.点击某一个内容时,其他的内容均呈现未点击状态。 目前实现的效果是 点开页面后,所有内容都为点击状态: [图片] 需要最终效果为: [图片][图片] 该组件的代码如下: import React, { memo, useCallback, useEffect, useMemo, useState } from 'react'; import PropTypes from 'prop-types'; import { View, Text, } from 'remax/wechat'; import { clearSearchBase64Url } from '@/actions/common' import { connect } from 'react-redux'; import useSysInfo from '../../hooks/sysInfo' import styles from './index.css'; const HelptitleItem = memo(function (props) { const { id, name } = props; const sysInfo = useSysInfo(); const [status, setStatus] = useState(1); const changeStatus1 = useCallback(() => { if (status) { setStatus(prev => prev === 0 ? 1 : 0) return; } else { setStatus(prev => prev === 1 ? 0 : 1) } }, [status]) function showmodal() { let data1 = { props } props.showModal(data1) } return ( <View className={styles.list}> <View className={styles.selectquestion} onTap={() => { showmodal() changeStatus1() }} style={(status) ? { "font-size": "30rpx", "color": "#1D1D1D;" } : { "font-size": "26rpx", "color": "#666666;" }}> <Text>{name}</Text> { (status) ? <View className={styles.greenline}></View> : null } </View> </View> ) }) HelptitleItem.propTypes = { id: PropTypes.string.isRequired, name: PropTypes.string.isRequired, } HelptitleItem.defaultProps = { } const mapStateToProps = (state) => { const { userInfo } = state.common return { userInfo } } const mapDispatchToProps = (dispatch) => { return { clearSearchBase64Url: () => { dispatch(clearSearchBase64Url()) } } } export default connect(mapStateToProps, mapDispatchToProps)(HelptitleItem); 怎么改代码让它正确实现?
2022-11-17 - 怎么解决赋值不上的问题?
从组件中获取到数据之后,要把id数据赋值给接口中的id,结果接口数据undefined?或者直接没赋值上,一直保持初始值不变。 部分代码如下: const [Id, setId] = useState(34); function showmodal(data1) { setId(data1.id) // setId(parseInt(data1.id)) console.log('获取导航栏id', data1) console.log('Id', Id) console.log('data1.Id', data1.id) getArticleList() } const getArticleList = useCallback((passPage) => { return request({ url: '/getArticleList', method: 'get', data: { type: 1, catalog_id: Id }, // success: function () { // articleDetails() // } }) }, [page]) { (list && list.length > 0) ? <ScrollView className={styles.top} // scrollY // refresherEnabled // refresherTriggered={refreshTriggered} lowerThreshold={60} bindscrolltolower={loadMore} bindrefresherrefresh={() => { // setRefreshTriggered(true) init(); }}> { list.map((v, i) => { return ( <HelptitleItem key={i} {...v} showModal={() => { showmodal(v) }} id="helptitleItem" /> ) }) } </ScrollView> : null } 运行截图: [图片] [图片]
2022-11-16