|
|
@@ -13,6 +13,7 @@ import Modal from "@/components/Modal";
|
|
|
import PickerViews from "@/components/PickerViews";
|
|
|
import LimitPickers from "@/components/LimitPickers";
|
|
|
import SlidngScale from "@/components/SlidngScale";
|
|
|
+import NoData from "@/components/NoData";
|
|
|
|
|
|
export default function Component(props: any) {
|
|
|
const user = useSelector((state: any) => state.user);
|
|
|
@@ -29,6 +30,8 @@ export default function Component(props: any) {
|
|
|
const [strTime, setStrTime] = useState('')
|
|
|
const [time, setTime] = useState(0)
|
|
|
|
|
|
+ const [showErrorPage, setErrorPage] = useState(false)
|
|
|
+
|
|
|
//未登录<->已登录 状态切换时,执行一次授权检查
|
|
|
useEffect(() => {
|
|
|
getCards();
|
|
|
@@ -49,7 +52,13 @@ export default function Component(props: any) {
|
|
|
function getCards() {
|
|
|
console.log('get Cards')
|
|
|
metricCards().then(res => {
|
|
|
+ setErrorPage(false)
|
|
|
setList((res as any).cards)
|
|
|
+ }).catch(e => {
|
|
|
+ if (list.length == 0) {
|
|
|
+ setErrorPage(true)
|
|
|
+ }
|
|
|
+ // console.log('请求超时')
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -239,73 +248,75 @@ export default function Component(props: any) {
|
|
|
|
|
|
const limit = new Date().getTime() - 180 * 3600 * 1000 * 24;
|
|
|
|
|
|
- return <View className="metric_container">
|
|
|
- {
|
|
|
- list.map((item: any, index: number) => {
|
|
|
- var unit = ''
|
|
|
- var value = '无记录'
|
|
|
- var desc = '记录解锁趋势'
|
|
|
- if (item.latest_record) {
|
|
|
- unit = item.schemas[0].default_unit
|
|
|
- value = getValues(item.latest_record.items)
|
|
|
- desc = TimeFormatter.formatTimestamp(item.latest_record.timestamp)
|
|
|
- }
|
|
|
- return <MetricItem title={item.name}
|
|
|
- value={value}
|
|
|
- unit={unit}
|
|
|
- desc={desc}
|
|
|
- btnText='记录'
|
|
|
- isDisabled={false}
|
|
|
- themeColor={item.theme_color}
|
|
|
- onClickDetail={() => { goDetail(item) }}
|
|
|
- onClick={() => { record(item) }}
|
|
|
- />
|
|
|
- })
|
|
|
- }
|
|
|
- <View className="space_width" />
|
|
|
- {
|
|
|
- isModalOpen && <Modal dismiss={closeModal}>
|
|
|
- <View style={{
|
|
|
- backgroundColor: 'white',
|
|
|
- display: 'flex', flexDirection: 'column',
|
|
|
- width: '100%', paddingBottom: 50, color: '#000'
|
|
|
- }}>
|
|
|
- <Text style={{ textAlign: 'center' }}>{(metricItem as any).name}</Text>
|
|
|
- <Text style={{ textAlign: 'center', paddingTop: 10, paddingBottom: 10, color: 'black' }} onClick={showTimePicker}>{strTime}</Text>
|
|
|
- <View style={{ position: 'relative' }}>
|
|
|
- {
|
|
|
- (metricItem as any).schemas.map((item, index) => {
|
|
|
- return <View key={index}>
|
|
|
- {
|
|
|
- (metricItem as any).schemas.length > 1 && <Text style={{ textAlign: 'center', width: '100%', display: 'flex', justifyContent: 'center' }}>{item.name}</Text>
|
|
|
- }
|
|
|
- <SlidngScale step={item.step} min={item.min} max={item.max} default_value={item.default_value}
|
|
|
- unit={item.default_unit}
|
|
|
- changed={(e) => { item.tempValue = e }} />
|
|
|
- </View>
|
|
|
- })
|
|
|
- }
|
|
|
- </View>
|
|
|
- <View style={{ marginBottom: 20, marginTop: 20, display: 'flex', flexDirection: 'row', width: '100%' }}>
|
|
|
- <Text style={{ flex: 1, textAlign: 'center', height: 50 }} onClick={cancelModal}>取消</Text>
|
|
|
- <Text style={{ flex: 1, textAlign: 'center', height: 50 }} onClick={confirmModal}>确认</Text>
|
|
|
- </View>
|
|
|
-
|
|
|
- </View>
|
|
|
- </Modal>
|
|
|
- }
|
|
|
- {
|
|
|
-
|
|
|
- isTimePickerOpen && <Modal dismiss={() => setIsTimePickerOpen(false)}>
|
|
|
- <LimitPickers isRealTime={true} time={time} limit={limit} limitDay={180} onCancel={() => { setIsTimePickerOpen(false) }} onChange={(e) => {
|
|
|
- chooseTime(e)
|
|
|
- // pickerConfirm(e)
|
|
|
- // hidePicker()
|
|
|
- }} />
|
|
|
- </Modal>
|
|
|
- }
|
|
|
- </View>
|
|
|
+ function detail() {
|
|
|
+ return <View className="metric_container">
|
|
|
+ {
|
|
|
+ list.map((item: any, index: number) => {
|
|
|
+ var unit = ''
|
|
|
+ var value = '无记录'
|
|
|
+ var desc = '记录解锁趋势'
|
|
|
+ if (item.latest_record) {
|
|
|
+ unit = item.schemas[0].default_unit
|
|
|
+ value = getValues(item.latest_record.items)
|
|
|
+ desc = TimeFormatter.formatTimestamp(item.latest_record.timestamp)
|
|
|
+ }
|
|
|
+ return <MetricItem title={item.name}
|
|
|
+ value={value}
|
|
|
+ unit={unit}
|
|
|
+ desc={desc}
|
|
|
+ btnText='记录'
|
|
|
+ isDisabled={false}
|
|
|
+ themeColor={item.theme_color}
|
|
|
+ onClickDetail={() => { goDetail(item) }}
|
|
|
+ onClick={() => { record(item) }}
|
|
|
+ />
|
|
|
+ })
|
|
|
+ }
|
|
|
+ <View className="space_width" />
|
|
|
+ {
|
|
|
+ isModalOpen && <Modal dismiss={closeModal}>
|
|
|
+ <View style={{
|
|
|
+ backgroundColor: 'white',
|
|
|
+ display: 'flex', flexDirection: 'column',
|
|
|
+ width: '100%', paddingBottom: 50, color: '#000'
|
|
|
+ }}>
|
|
|
+ <Text style={{ textAlign: 'center' }}>{(metricItem as any).name}</Text>
|
|
|
+ <Text style={{ textAlign: 'center', paddingTop: 10, paddingBottom: 10, color: 'black' }} onClick={showTimePicker}>{strTime}</Text>
|
|
|
+ <View style={{ position: 'relative' }}>
|
|
|
+ {
|
|
|
+ (metricItem as any).schemas.map((item, index) => {
|
|
|
+ return <View key={index}>
|
|
|
+ {
|
|
|
+ (metricItem as any).schemas.length > 1 && <Text style={{ textAlign: 'center', width: '100%', display: 'flex', justifyContent: 'center' }}>{item.name}</Text>
|
|
|
+ }
|
|
|
+ <SlidngScale step={item.step} min={item.min} max={item.max} default_value={item.default_value}
|
|
|
+ unit={item.default_unit}
|
|
|
+ changed={(e) => { item.tempValue = e }} />
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ <View style={{ marginBottom: 20, marginTop: 20, display: 'flex', flexDirection: 'row', width: '100%' }}>
|
|
|
+ <Text style={{ flex: 1, textAlign: 'center', height: 50 }} onClick={cancelModal}>取消</Text>
|
|
|
+ <Text style={{ flex: 1, textAlign: 'center', height: 50 }} onClick={confirmModal}>确认</Text>
|
|
|
+ </View>
|
|
|
|
|
|
+ </View>
|
|
|
+ </Modal>
|
|
|
+ }
|
|
|
+ {
|
|
|
+
|
|
|
+ isTimePickerOpen && <Modal dismiss={() => setIsTimePickerOpen(false)}>
|
|
|
+ <LimitPickers isRealTime={true} time={time} limit={limit} limitDay={180} onCancel={() => { setIsTimePickerOpen(false) }} onChange={(e) => {
|
|
|
+ chooseTime(e)
|
|
|
+ // pickerConfirm(e)
|
|
|
+ // hidePicker()
|
|
|
+ }} />
|
|
|
+ </Modal>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ }
|
|
|
|
|
|
+ return showErrorPage ? <NoData refresh={() => { getCards() }} /> : detail()
|
|
|
|
|
|
}
|