panhui 5 лет назад
Родитель
Сommit
a80aae22eb
6 измененных файлов с 88 добавлено и 38 удалено
  1. 24 8
      components/UpLoadImage.js
  2. 12 0
      models/couponModel.js
  3. 21 15
      models/userModel.js
  4. 4 1
      models/verifiedModel.js
  5. 24 11
      screens/EditBannerScreen.js
  6. 3 3
      screens/HomeScreen.js

+ 24 - 8
components/UpLoadImage.js

@@ -10,7 +10,7 @@ import { useModel } from "flooks";
 import * as ImagePicker from "expo-image-picker";
 import { Image, Platform } from "react-native";
 
-const _pickImage = loading => {
+const _pickImage = (loading, aspect) => {
   return ImagePicker.requestCameraRollPermissionsAsync()
     .then(res => {
       if (!res.granted) {
@@ -19,8 +19,8 @@ const _pickImage = loading => {
         return ImagePicker.launchImageLibraryAsync({
           mediaTypes: ImagePicker.MediaTypeOptions.Images,
           allowsEditing: true,
-          aspect: [1, 1],
-          quality: 1,
+          aspect: aspect || [(1, 1)],
+          quality: 0.6,
           base64: true,
         });
       }
@@ -43,17 +43,33 @@ export default function UpLoadImage(props) {
   const { loading } = useModel("loadingModel", true);
   // eslint-disable-next-line no-shadow
   const renderPulseIcon = props => <Icon {...props} name="plus-outline" />;
+  const { aspect, size } = props;
+
+  const width = React.useMemo(() => {
+    if (size) {
+      return size;
+    } else {
+      return 67;
+    }
+  }, [size, aspect]);
+
+  const height = React.useMemo(() => {
+    if (size && aspect) {
+      return (size / aspect[0]) * aspect[1];
+    } else if (size) {
+      return size;
+    } else {
+      return 67;
+    }
+  }, [size, aspect]);
 
   return (
     <>
       <Button
-        style={[
-          props.style,
-          props.size ? { width: props.size, height: props.size } : {},
-        ]}
+        style={[props.style, { width, height }]}
         appearance="imageButton"
         onPress={() => {
-          _pickImage(loading).then(img => {
+          _pickImage(loading, aspect).then(img => {
             httpPost("/upload/base64", {
               base64: img,
             }).then(res => {

+ 12 - 0
models/couponModel.js

@@ -10,6 +10,18 @@ export default {
     couponList: [],
   },
   actions: ({ model, setState }) => ({
+    // 获取能用的优惠券
+    getPlaf() {
+      const { mid } = model("userModel");
+      const { httpGet } = model("httpModel");
+      return httpGet(
+        "/coupon/my",
+        {
+          isAll: false,
+        },
+        true
+      );
+    },
     // 获取商家优惠券
     getMyList(page, size) {
       const { mid } = model("userModel");

+ 21 - 15
models/userModel.js

@@ -26,7 +26,7 @@ export default {
       const { updateUser } = model();
       const { httpGet } = model("httpModel");
       const { changeVerfied } = model("verifiedModel");
-      return httpGet("/merchant/my")
+      return httpGet("/merchant/my", {}, true)
         .then(res => {
           const _res = { ...res };
           if (_res) {
@@ -219,22 +219,28 @@ export default {
     userLogout() {
       const { removeAsyncStorage } = model("httpModel");
       const { success } = model("loadingModel");
+      const { saveVeriFied } = model("verifiedModel");
 
-      return removeAsyncStorage("token").then(() => {
-        setState({
-          mid: 0,
-          name: "未登录",
-          showName: "未登录",
-          phone: "",
-          isLogin: false,
-          guideStep: "0",
-          registerInfo: null,
-          initApp: true,
-          refreashReason: "loginOut",
-          userId: "",
+      return removeAsyncStorage("token")
+        .then(() => {
+          setState({
+            mid: 0,
+            name: "未登录",
+            showName: "未登录",
+            phone: "",
+            isLogin: false,
+            guideStep: "0",
+            registerInfo: null,
+            initApp: true,
+            refreashReason: "loginOut",
+            userId: "",
+          });
+          // 清空认证信息
+          return saveVeriFied({});
+        })
+        .then(() => {
+          success("退出成功");
         });
-        success("退出成功");
-      });
     },
     getGuideStep() {
       const { mid, status } = model();

+ 4 - 1
models/verifiedModel.js

@@ -12,7 +12,8 @@ export default {
         "/verified/my",
         {
           userId,
-        },true
+        },
+        true
       ).then(res => {
         setState({
           verifiedInfo: res,
@@ -52,11 +53,13 @@ export default {
         ).then(res => {
           setState({
             verifiedInfo: res,
+            registerVerifiedInfo: {},
           });
         });
       } else {
         setState({
           registerVerifiedInfo: info,
+          verifiedInfo: {},
         });
         return Promise.resolve();
       }

+ 24 - 11
screens/EditBannerScreen.js

@@ -46,8 +46,6 @@ const styles = StyleSheet.create({
   },
   upload: {
     marginTop: 21,
-    width: 133,
-    height: 133,
     alignSelf: "center",
   },
   main: {
@@ -58,6 +56,10 @@ const styles = StyleSheet.create({
     alignSelf: "center",
     marginTop: 19,
   },
+  title: {
+    flexDirection: "row",
+    alignItems: "center",
+  },
 });
 
 export default function EditBannerScreen({ route }) {
@@ -73,6 +75,7 @@ export default function EditBannerScreen({ route }) {
   const [img, changeImg] = React.useState("");
   const [type, setType] = React.useState("banner");
   const { showDialog } = useModel("dialogModel");
+  const { loading, success } = useModel("loadingModel");
   const {
     bannerTitle,
     logoTitle,
@@ -137,27 +140,37 @@ export default function EditBannerScreen({ route }) {
             </Button>
           </Layout>
           <Layout style={styles.main}>
-            <Text category="c1">
-              {uplaodText +
-                (type === "banner"
-                  ? bannerTitle
-                  : type === "qualification"
-                  ? qualificationTitle
-                  : logoTitle)}
-            </Text>
+            <Layout style={styles.title}>
+              <Text category="s1">
+                {uplaodText +
+                  (type === "banner"
+                    ? bannerTitle
+                    : type === "qualification"
+                    ? qualificationTitle
+                    : logoTitle)}
+              </Text>
+              {type === "banner" && (
+                <Text category="h1" status="info" style={{ paddingLeft: 10 }}>
+                  建议尺寸:720*240
+                </Text>
+              )}
+            </Layout>
             <UpLoadImage
               style={styles.upload}
               value={img}
               changeIcon={changeImg}
-              size={133}
+              aspect={type === "banner" ? [3, 1] : [1, 1]}
+              size={type === "banner" ? 240 : 133}
             />
 
             <Button
               disabled={!img}
               style={styles.button}
               onPress={() => {
+                loading();
                 uploadStoreImg(img, type).then(() => {
                   changeImg("");
+                  success("上传成功");
                 });
               }}
             >

+ 3 - 3
screens/HomeScreen.js

@@ -194,7 +194,7 @@ export default function HomeScreen({ navigation, route }) {
   const [fullReductions, changeFllReduction] = React.useState([]);
   const { showDialog } = useModel("dialogModel", true);
   const { httpGet } = useModel("httpModel", true);
-  const { getMyList } = useModel("couponModel", true);
+  const { getPlaf } = useModel("couponModel", true);
 
   const [showMore, changeShow] = React.useState(false);
 
@@ -216,8 +216,8 @@ export default function HomeScreen({ navigation, route }) {
       httpGet("/fullReduction/my").then(res => {
         changeFllReduction(res);
       });
-      getMyList(0, 5).then(res => {
-        setCouponList(res.content);
+      getPlaf().then(res => {
+        setCouponList(res);
       });
     }, [])
   );