Commit cc82f5a5 authored by Friends233's avatar Friends233

首页store

parent 4a9d56e0
import API from "@src/api"
import { addLoading } from "@src/utils/utils"
export default {
/** 首页数据 */
homeInfo:{},
/** 设置首页数据 */
setHomeInfo(data){
this.homeInfo = data
},
/** 获取首页数据 */
async getHomeInfo(){
addLoading(async () => {
const res = await API.homeInfo()
if(res && res.success) {
this.setHomeInfo(res.data)
}
})
}
}
\ No newline at end of file
/* /*
* @Author: super * @Author: super
* @Date: 2021-01-20 14:08:27 * @Date: 2021-01-20 14:08:27
* @LastEditTime: 2023-02-01 15:35:57 * @LastEditTime: 2023-03-20 11:26:25
* @LastEditors: Please set LastEditors * @LastEditors: Please set LastEditors
* @Description: * @Description:
*/ */
...@@ -16,6 +16,7 @@ export const MODAL_INDEX = { ...@@ -16,6 +16,7 @@ export const MODAL_INDEX = {
*/ */
export function ERROR_MESSAGE(errorCode) { export function ERROR_MESSAGE(errorCode) {
let message = ""; let message = "";
errorCode = Number(errorCode)
switch (errorCode) { switch (errorCode) {
// case 999101: // case 999101:
// message = "登录已过期"; // message = "登录已过期";
......
/* /*
* @Author: all * @Author: all
* @Date: 2021-11-01 09:30:00 * @Date: 2021-11-01 09:30:00
* @LastEditTime: 2021-11-02 18:30:00 * @LastEditTime: 2023-03-20 11:25:59
* @LastEditors: all * @LastEditors: Please set LastEditors
* @Description: * @Description:
*/ */
import { Toast } from "@spark/ui"; import { hideLoading, showLoading, Toast } from "@spark/ui";
import { ERROR_MESSAGE } from "./constants" import { ERROR_MESSAGE } from "./constants"
import { useRef, useEffect, useCallback } from "react"; import { useRef, useEffect, useCallback } from "react";
...@@ -37,7 +37,7 @@ export { ...@@ -37,7 +37,7 @@ export {
*/ */
/** */ /** */
function showToast(errCode, message) { function showToast(errCode, message) {
Toast(ERROR_MESSAGE[errCode] || message || "网络异常,请稍后再试~", 2000, {hideOthers:true}); Toast(ERROR_MESSAGE(errCode) || message || "网络异常,请稍后再试~", 2000, {hideOthers:true});
} }
/** /**
...@@ -379,4 +379,18 @@ const onCtrScroll = (flag = true) => { ...@@ -379,4 +379,18 @@ const onCtrScroll = (flag = true) => {
} else { // 开启滚动 } else { // 开启滚动
document.body.removeEventListener('touchmove', bodyScroll, { passive: false }); document.body.removeEventListener('touchmove', bodyScroll, { passive: false });
} }
}
/** 添加一个loading */
export const addLoading = async (fn) => {
let res = null
try {
showLoading()
res = await fn()
} catch (err) {
showToast(err.code, err.message)
} finally {
hideLoading()
}
return Promise.resolve(res)
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment