EditBannerScreen.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import * as WebBrowser from "expo-web-browser";
  2. import * as React from "react";
  3. import { Image, StyleSheet } from "react-native";
  4. import { Layout, Text, useTheme, Button } from "@ui-kitten/components";
  5. import { useFocusEffect } from "@react-navigation/native";
  6. import { useModel } from "flooks";
  7. import ScrollPage from "../components/ScrollPage";
  8. import NavHeaderBar from "../components/NavHeaderBar";
  9. import UpLoadImage from "../components/UpLoadImage";
  10. const styles = StyleSheet.create({
  11. container: {
  12. flex: 1,
  13. paddingBottom: 33,
  14. },
  15. icon: {
  16. width: 90,
  17. height: 80,
  18. marginBottom: 26,
  19. },
  20. text: {
  21. fontWeight: "500",
  22. marginBottom: 7,
  23. },
  24. top: {
  25. paddingVertical: 7,
  26. height: 114,
  27. backgroundColor: "#eee",
  28. alignSelf: "stretch",
  29. alignItems: "center",
  30. justifyContent: "center",
  31. },
  32. banner: {
  33. flex: 1,
  34. alignSelf: "stretch",
  35. },
  36. logo: {
  37. width: 50,
  38. height: 50,
  39. borderRadius: 3,
  40. },
  41. remove: {
  42. position: "absolute",
  43. bottom: 10,
  44. right: 10,
  45. },
  46. upload: {
  47. marginTop: 21,
  48. alignSelf: "center",
  49. },
  50. main: {
  51. paddingHorizontal: 24,
  52. paddingVertical: 14,
  53. },
  54. button: {
  55. alignSelf: "center",
  56. marginTop: 19,
  57. },
  58. title: {
  59. flexDirection: "row",
  60. alignItems: "center",
  61. },
  62. });
  63. export default function EditBannerScreen({ route }) {
  64. const theme = useTheme();
  65. const { changeBackground } = useModel("barModel");
  66. const {
  67. banner,
  68. logo,
  69. qualification,
  70. uploadStoreImg,
  71. registerInfo,
  72. } = useModel("userModel");
  73. const [img, changeImg] = React.useState("");
  74. const [type, setType] = React.useState("banner");
  75. const { showDialog } = useModel("dialogModel");
  76. const { loading, success } = useModel("loadingModel");
  77. const {
  78. bannerTitle,
  79. logoTitle,
  80. qualificationTitle,
  81. remove,
  82. editText,
  83. uplaodText,
  84. uplaodImg,
  85. removeTips,
  86. FPMPMG,
  87. successText,
  88. } = useModel("wordsModel");
  89. useFocusEffect(
  90. React.useCallback(() => {
  91. changeBackground(theme["color-primary-500"]);
  92. if (route.params.type) {
  93. setType(route.params.type);
  94. }
  95. }, [])
  96. );
  97. return (
  98. <>
  99. <NavHeaderBar
  100. title={
  101. editText +
  102. (type === "banner"
  103. ? bannerTitle
  104. : type === "qualification"
  105. ? qualificationTitle
  106. : logoTitle)
  107. }
  108. />
  109. <ScrollPage>
  110. <Layout style={styles.container}>
  111. <Layout style={styles.top}>
  112. <Image
  113. source={{
  114. uri:
  115. type === "banner"
  116. ? banner
  117. : type === "qualification"
  118. ? qualification || registerInfo.qualification
  119. : logo,
  120. }}
  121. style={[type === "logo" ? styles.logo : styles.banner]}
  122. />
  123. <Button
  124. style={styles.remove}
  125. size="tiny"
  126. status="danger"
  127. onPress={() => {
  128. showDialog({
  129. bodyText: removeTips,
  130. status: "danger",
  131. cancelable: true,
  132. confirmCallback: () => {
  133. uploadStoreImg("", type);
  134. },
  135. });
  136. }}
  137. >
  138. {remove}
  139. </Button>
  140. </Layout>
  141. <Layout style={styles.main}>
  142. <Layout style={styles.title}>
  143. <Text category="s1">
  144. {uplaodText +
  145. (type === "banner"
  146. ? bannerTitle
  147. : type === "qualification"
  148. ? qualificationTitle
  149. : logoTitle)}
  150. </Text>
  151. {type === "banner" && (
  152. <Text category="h1" status="info" style={{ paddingLeft: 10 }}>
  153. 建议尺寸:720*240
  154. </Text>
  155. )}
  156. </Layout>
  157. <UpLoadImage
  158. style={styles.upload}
  159. value={img}
  160. changeIcon={changeImg}
  161. aspect={type === "banner" ? [3, 1] : [1, 1]}
  162. size={type === "banner" ? 240 : 133}
  163. />
  164. <Button
  165. disabled={!img}
  166. style={styles.button}
  167. onPress={() => {
  168. loading();
  169. uploadStoreImg(img, type).then(() => {
  170. changeImg("");
  171. success(FPMPMG + successText);
  172. });
  173. }}
  174. >
  175. {uplaodImg}
  176. </Button>
  177. </Layout>
  178. </Layout>
  179. </ScrollPage>
  180. </>
  181. );
  182. }