loadingModel.js 3.1 KB

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