LinksScreen.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { Ionicons } from "@expo/vector-icons";
  2. import * as WebBrowser from "expo-web-browser";
  3. import * as React from "react";
  4. import { StyleSheet, Text, View, Button, Picker } from "react-native";
  5. import { RectButton, ScrollView } from "react-native-gesture-handler";
  6. import axios from "axios";
  7. import { useFocusEffect } from "@react-navigation/native";
  8. export default function LinksScreen() {
  9. const [token, setToken] = React.useState("");
  10. const [error, setError] = React.useState("");
  11. const [check, changeCheck] = React.useState(true);
  12. const [order, setOrder] = React.useState(0);
  13. const [selectOrderId, changeOrder] = React.useState(0);
  14. React.useEffect(() => {
  15. if (token) {
  16. console.log(token);
  17. axiosInstance.get("/orderInfo/all").then((res) => {
  18. console.log(res.content);
  19. setOrder(res.content);
  20. });
  21. }
  22. }, [token, check]);
  23. const axiosInstance = React.useMemo(() => {
  24. let axiosInstance = axios.create({
  25. baseURL: "http://dingdong.izouma.com",
  26. });
  27. axiosInstance.interceptors.request.use(
  28. (config) => {
  29. config.headers = config.headers || {};
  30. if (token) {
  31. config.headers["Authorization"] = "Bearer " + token;
  32. }
  33. return config;
  34. },
  35. (error) => {
  36. return Promise.reject(error);
  37. }
  38. );
  39. axiosInstance.interceptors.response.use(
  40. (response) => {
  41. setError("");
  42. return response.data;
  43. },
  44. (error) => {
  45. setError(error.response.data.error);
  46. return Promise.reject(error.response.data);
  47. }
  48. );
  49. return axiosInstance;
  50. }, [token]);
  51. useFocusEffect(
  52. React.useCallback(() => {
  53. var data = new FormData();
  54. data.append("username", "qs");
  55. data.append("password", "123");
  56. axiosInstance
  57. .post("/auth/login", data, {
  58. withCredentials: true,
  59. })
  60. .then((res) => {
  61. setToken(res);
  62. });
  63. }, [])
  64. );
  65. const OrderInfos = () => {
  66. return order.map((item) => (
  67. <Picker.Item
  68. label={
  69. "订单id:" +
  70. item.id +
  71. "---用户id:" +
  72. item.userId +
  73. "商家id:" +
  74. item.merchantId
  75. }
  76. value={item.id}
  77. key={item.id}
  78. />
  79. ));
  80. };
  81. return (
  82. <View style={styles.container}>
  83. {order.length > 0 && (
  84. <Picker
  85. selectedValue={selectOrderId}
  86. style={{ height: 50, width: 200 }}
  87. onValueChange={(itemValue, itemIndex) =>
  88. changeOrder(itemValue)
  89. }
  90. >
  91. {OrderInfos()}
  92. </Picker>
  93. )}
  94. {/* {selectOrderId != 0 && <Button title='接单' onPress={() => {}} />} */}
  95. </View>
  96. );
  97. }
  98. const styles = StyleSheet.create({
  99. container: {
  100. flex: 1,
  101. backgroundColor: "#fafafa",
  102. alignItems: "center",
  103. justifyContent: "space-around",
  104. },
  105. contentContainer: {
  106. paddingTop: 15,
  107. },
  108. optionIconContainer: {
  109. marginRight: 12,
  110. },
  111. option: {
  112. backgroundColor: "#fdfdfd",
  113. paddingHorizontal: 15,
  114. paddingVertical: 15,
  115. borderWidth: StyleSheet.hairlineWidth,
  116. borderBottomWidth: 0,
  117. borderColor: "#ededed",
  118. },
  119. lastOption: {
  120. borderBottomWidth: StyleSheet.hairlineWidth,
  121. },
  122. optionText: {
  123. fontSize: 15,
  124. alignSelf: "flex-start",
  125. marginTop: 1,
  126. },
  127. });