loadingModel.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React from "react";
  2. import { TopviewGetInstance, Icon, Tip } from "beeshell";
  3. import { View, Text, ActivityIndicator, StyleSheet } from "react-native";
  4. //加载页
  5. export default {
  6. state: {
  7. status: "",
  8. title: "",
  9. show: false,
  10. loadingId: 0,
  11. successId: 0,
  12. },
  13. actions: ({ model, setState }) => ({
  14. loading() {
  15. console.log("loading");
  16. const { clear } = model();
  17. clear();
  18. TopviewGetInstance()
  19. .add(<LoadingComent />)
  20. .then((id) => {
  21. setState({
  22. status: "loading",
  23. show: true,
  24. loadingId: id,
  25. });
  26. });
  27. },
  28. success(title) {
  29. const { clear } = model();
  30. clear();
  31. TopviewGetInstance()
  32. .add(<SuccessComent title={title} />)
  33. .then((id) => {
  34. setState({
  35. status: "success",
  36. title: title,
  37. show: true,
  38. successId: id,
  39. });
  40. setTimeout(() => clear(), 1500);
  41. });
  42. },
  43. warnning(title) {
  44. const { clear } = model();
  45. clear();
  46. setState({
  47. status: "warn",
  48. title: title,
  49. show: true,
  50. });
  51. Tip.show(title || "", 1500, false);
  52. setTimeout(() => clear(), 1500);
  53. },
  54. clear() {
  55. const { show, status, loadingId, successId } = model();
  56. if (show) {
  57. if (status === "loading") {
  58. TopviewGetInstance().remove(loadingId);
  59. } else if (status === "success") {
  60. TopviewGetInstance().remove(successId);
  61. }
  62. setState({
  63. show: false,
  64. });
  65. }
  66. },
  67. }),
  68. };
  69. const LoadingComent = () => (
  70. <View style={styles.box}>
  71. <View style={styles.loadingBox}>
  72. <ActivityIndicator size='large' color='#fff' />
  73. <Text style={styles.text}>加载中</Text>
  74. </View>
  75. </View>
  76. );
  77. const SuccessComent = (props) => (
  78. <View style={styles.box}>
  79. <View style={styles.loadingBox}>
  80. <Icon
  81. source={require("beeshell/dist/common/images/icons/check.png")}
  82. size={60}
  83. tintColor='#fff'
  84. />
  85. <Text style={styles.text}>{props.title || "成功"}</Text>
  86. </View>
  87. </View>
  88. );
  89. const styles = StyleSheet.create({
  90. box: {
  91. position: "absolute",
  92. left: 0,
  93. right: 0,
  94. top: 0,
  95. bottom: 0,
  96. backgroundColor: "rgba(255,255,255,0)",
  97. alignItems: "center",
  98. justifyContent: "center",
  99. },
  100. loadingBox: {
  101. width: 120,
  102. height: 120,
  103. borderRadius: 10,
  104. backgroundColor: "rgba(0,0,0,0.8)",
  105. alignItems: "center",
  106. justifyContent: "center",
  107. },
  108. text: {
  109. color: "#fff",
  110. marginTop: 5,
  111. },
  112. });