From bbe59568133b5222ffa67347f1b9ece97f42dc04 Mon Sep 17 00:00:00 2001 From: czm <2192718639@qq.com> Date: Tue, 24 May 2022 20:32:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E9=A1=B5=E9=9D=A2=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/onlinePay.ts | 12 ++ src/api/order.ts | 4 +- src/common/constant.js | 3 +- src/components/searchInput/index.tsx | 2 +- .../addressInfoDetail/index.module.scss | 111 ++++++++++++++++++ .../components/addressInfoDetail/index.tsx | 87 ++++++++++++++ src/pages/order/components/kindList/index.tsx | 28 ++--- .../components/orderState/index.module.scss | 3 +- .../order/components/orderState/index.tsx | 49 ++++---- src/pages/order/components/payment/index.tsx | 2 +- src/pages/order/components/scanPay/index.tsx | 88 ++++++++++++-- src/pages/order/index.tsx | 73 ++++-------- src/styles/iconfont.scss | 22 +++- src/styles/iconfont.ttf | Bin 10856 -> 12196 bytes src/use/useCheckAuthorize.tsx | 51 ++++++++ src/use/useHttp.ts | 8 +- 16 files changed, 430 insertions(+), 113 deletions(-) create mode 100644 src/api/onlinePay.ts create mode 100644 src/pages/order/components/addressInfoDetail/index.module.scss create mode 100644 src/pages/order/components/addressInfoDetail/index.tsx create mode 100644 src/use/useCheckAuthorize.tsx diff --git a/src/api/onlinePay.ts b/src/api/onlinePay.ts new file mode 100644 index 0000000..3c23414 --- /dev/null +++ b/src/api/onlinePay.ts @@ -0,0 +1,12 @@ +import { useRequest } from "@/use/useHttp" + +/** + * 获取在线支付二维码 + */ + export const GetPayCode = () => { + return useRequest({ + url: `/`, + base_url: 'http://192.168.1.127:8081', + method: "post", + }) +} \ No newline at end of file diff --git a/src/api/order.ts b/src/api/order.ts index 10318d3..a1eb29f 100644 --- a/src/api/order.ts +++ b/src/api/order.ts @@ -21,11 +21,11 @@ export const SaleOrderApi = () => { } /** - * 获取销售单详情 + * 获取商城待配布订单详情 */ export const GetSaleOrderDetailApi = () => { return useRequest({ - url: `/v1/mall/saleOrder`, + url: `/v1/mall/saleOrder/arranging`, method: "get", }) } diff --git a/src/common/constant.js b/src/common/constant.js index 734263a..f62112f 100644 --- a/src/common/constant.js +++ b/src/common/constant.js @@ -8,8 +8,9 @@ // export const BASE_URL = `http://192.168.1.30:40001/lymarket` // 发 // export const BASE_URL = `https://dev.zzfzyc.com/lymarket` // 开发环境 // export const BASE_URL = `https://www.zzfzyc.com/lymarket` // 正式环境 -export const BASE_URL = `http://192.168.1.4:40001/lymarket` // 王霞 +// export const BASE_URL = `http://192.168.1.4:40001/lymarket` // 王霞 // export const BASE_URL = `http://192.168.1.224:50002/lymarket` // 添 +export const BASE_URL = `http://192.168.1.15:50001/lymarket` // 杰 // CDN // 生成密钥 diff --git a/src/components/searchInput/index.tsx b/src/components/searchInput/index.tsx index 48c45fc..4fe82cd 100644 --- a/src/components/searchInput/index.tsx +++ b/src/components/searchInput/index.tsx @@ -38,7 +38,7 @@ export default memo((props: Params) => { return {} }, [showBorder]) return ( - + {showTitle&&{title}} {!props.children&& clickOnInput?.()} onInput={(e) => changeOnInput?.(e.detail.value)}/> diff --git a/src/pages/order/components/addressInfoDetail/index.module.scss b/src/pages/order/components/addressInfoDetail/index.module.scss new file mode 100644 index 0000000..b4a9f1b --- /dev/null +++ b/src/pages/order/components/addressInfoDetail/index.module.scss @@ -0,0 +1,111 @@ +.order_address{ + height: 178px; + background: #ffffff; + border-radius: 20px; + display: flex; + align-items: center; + padding: 30px; + box-sizing: border-box; + margin-top: 20px; + position: relative; + .order_address_icon{ + font-size: 50px; + color: $color_main; + position: absolute; + top: 35px; + left: 20px; + } + .order_address_text_con{ + flex:1; + padding-left: 50px; + box-sizing: border-box; + height: 100%; + display: flex; + flex-direction: column; + justify-content: space-between; + .order_address_text_title{ + font-size: $font_size_medium; + margin-top: 10px; + @include common_ellipsis; + display: flex; + align-items: center; + justify-content: space-between; + .moreIconfont{ + font-size: 20px; + } + } + .order_address_text_name{ + + align-items: center; + text{ + &:nth-child(1) { + color: #000; + font-weight: 700; + font-size: $color_font_one; + margin-right: 40px; + } + &:nth-child(2) { + color: $color_font_one; + font-size: $font_size_medium; + } + } + } + } + .updateBtn{ + width:200px; + font-size: $font_size_min; + background-color: #F0F0F0; + height: 64px; + border-radius: 24px; + color: $color_font_two; + position: absolute; + bottom: 10px; + right: 10px; + .updateBtn_list{ + position: absolute; + display: flex; + z-index: 5; + width: 100%; + .updateBtn_item_select{ + color: #fff; + } + } + .updateBtn_item{ + flex:1; + text-align: center; + line-height: 64px; + } + .updateBtn_select{ + color: #fff; + background-color: $color_main; + border-radius: 24px; + position: absolute; + width: 100px; + height: 61px; + z-index: 1; + transition: all 0.3s ease-in-out; + } + + } + .order_address_text_no{ + flex: 1; + font-size: $font_size; + font-weight: 700; + margin-left: 30px; + } + .order_address_more_icon{ + color: $color_font_three; + font-size: $font_size; + } + +} +.order_address_list { + height: 900px; + .order_address_title{ + font-size: $font_size; + font-weight: 700; + width: 100%; + text-align: center; + padding: 20px 0 30px 0; + } +} \ No newline at end of file diff --git a/src/pages/order/components/addressInfoDetail/index.tsx b/src/pages/order/components/addressInfoDetail/index.tsx new file mode 100644 index 0000000..4675aec --- /dev/null +++ b/src/pages/order/components/addressInfoDetail/index.tsx @@ -0,0 +1,87 @@ +import AddressList from "@/components/AddressList"; +import Popup from "@/components/popup"; +import { Text, View } from "@tarojs/components" +import classnames from "classnames"; +import { memo, useCallback, useEffect, useMemo, useState } from "react"; +import styles from './index.module.scss' + +export type AddressInfoParam = { + province_name: string, + city_name: string, + district_name: string, + address_detail: string, + id?: number, + name: string, + phone: string +} +type Param = { + onSelect?: (val:any) => void, //选择 + defaultValue?: AddressInfoParam|null //默认值 + disabled?: false|true //true禁用后只用于展示 + shipment_mode?: 1|2 //1自提 2物流 +} + +export default memo(({onSelect, defaultValue = null, disabled = false, shipment_mode = 1}: Param) => { + const [showAddressList, setShowAddressList] = useState(false) + + useEffect(() => { + setUserInfo(() => defaultValue) + }, [defaultValue]) + + //选择地址 + const [userInfo, setUserInfo] = useState() + const getAddress = useCallback((val) => { + setShowAddressList(() => false) + setUserInfo(() => val) + onSelect?.(val) + }, []) + + //地址格式 + const formatAddress = useMemo(() => { + if(userInfo) + return userInfo.province_name + userInfo.city_name + userInfo.district_name + userInfo.address_detail + }, [userInfo]) + + const changeShow = () => { + if(receivingStatus == 2) + setShowAddressList(() => true) + } + //收货方法,1:自提,2物流 + const [receivingStatus, setReceivingStatus] = useState(1) + const onReceivingStatus = (val) => { + setReceivingStatus(val) + } + useEffect(() => { + setReceivingStatus(() => shipment_mode) + }, [shipment_mode]) + return ( + + changeShow()}> + + + + {formatAddress} + {(receivingStatus == 2)&&} + + + {userInfo?.name} + {userInfo?.phone} + + + + + onReceivingStatus(1)}>自提 + onReceivingStatus(2)}>物流 + + + + + {!disabled&& setShowAddressList(false)}> + + 请选择收货地址 + getAddress(item)}/> + + } + + ) +}) \ No newline at end of file diff --git a/src/pages/order/components/kindList/index.tsx b/src/pages/order/components/kindList/index.tsx index 1a42f7e..34d9542 100644 --- a/src/pages/order/components/kindList/index.tsx +++ b/src/pages/order/components/kindList/index.tsx @@ -6,13 +6,13 @@ import styles from './index.module.scss' type OrderParam = { estimate_amount: number, - estimate_weight: number, list: any[], sale_mode: number, - sale_mode_name: string + sale_mode_name: string, unit: string, - colo_count: number, - num_count: number + total_colors: number, + total_fabrics: number, + total_number: number } @@ -22,14 +22,14 @@ export default memo(({value}:{value:OrderParam|null}) => { return value?.sale_mode == 0? item.roll : Number(item.length / 100) }, [value]) //对应单价 - const standardPrice = useCallback(item => { - return formatPriceDiv(item.standard_price).toLocaleString() + '/' + (value?.sale_mode == 1?'m':'kg') + const standardPrice = useCallback(price => { + return formatPriceDiv(price).toLocaleString() + '/' + (value?.sale_mode == 1?'m':'kg') }, [value]) //数量格式 const numText = useMemo(() => { if(value) - return `${value?.list.length}种面料,${value?.colo_count}种颜色,共${value?.num_count }${value?.unit}` + return `${value?.total_fabrics}种面料,${value?.total_colors}种颜色,共${value?.total_number}${value?.unit}` }, [value]) return ( <> @@ -39,18 +39,18 @@ export default memo(({value}:{value:OrderParam|null}) => { value?.list.map(item => { return - {item.sale_mode_name} - {formatHashTag(item.product_code, item.product_name)} - 共{item.color_list.length}种 + {value.sale_mode_name} + {formatHashTag(item.code, item.name)} + 共{item?.product_colors.length}种 - {item.color_list?.map(colorItem => { - return + {item?.product_colors?.map(colorItem => { + return - {colorItem.product_color_code + ' ' + colorItem.product_color_name} - ¥{standardPrice(colorItem)} + {colorItem.code + ' ' + colorItem.name} + ¥{standardPrice(colorItem.sale_price)} ×{formatCount(colorItem)}{value.unit} diff --git a/src/pages/order/components/orderState/index.module.scss b/src/pages/order/components/orderState/index.module.scss index 195c10d..c1aef8a 100644 --- a/src/pages/order/components/orderState/index.module.scss +++ b/src/pages/order/components/orderState/index.module.scss @@ -16,7 +16,6 @@ .order_status_item{ position: relative; padding-left: 50px; - min-height: 120px; .order_status_tail_end, .order_status_tail{ width: 15px; height: 15px; @@ -44,7 +43,7 @@ align-items: center; .order_status_title{ color: $color_font_two; - font-size: $font_size_big; + font-size: $font_size; font-weight: 700; } .order_status_time{ diff --git a/src/pages/order/components/orderState/index.tsx b/src/pages/order/components/orderState/index.tsx index 7592c74..a3b51bb 100644 --- a/src/pages/order/components/orderState/index.tsx +++ b/src/pages/order/components/orderState/index.tsx @@ -4,7 +4,7 @@ import styles from './index.module.scss' import classnames from "classnames"; import { formatImgUrl } from "@/common/fotmat"; type Param = { - title: string, + status: string, time: string, tag: string, desc: string @@ -14,33 +14,30 @@ export default memo(({list = []}:{list?:Param[]}) => { const changeMore = () => { setShowMore(() => !showMore) } - list = [ - {title:'待配布', time:'2022-04-24 09:08', tag:'已接单', desc:'仓库正在为你配布...'}, - {title:'待配布', time:'2022-04-24 09:08', tag:'已接单', desc:'仓库正在为你配布...'}, - {title:'待接单', time:'2022-04-24 09:08', tag:'已提交', desc:''}, - ] return ( - - - {list.map((item, index) => - {(list.length > 1)&&} - {(list.length != (index + 1))&&} - - {item.title} - {item.time} - {item.tag} - - {item.desc} - )} - - {(list.length > 2) && changeMore()}> - {showMore&&'收起物流详情'||'点击查看更多物流详情'} - + <> + {(list.length > 0)&& + + {list.map((item, index) => + {(list.length > 1)&&} + {(list.length != (index + 1))&&} + + {item.status} + {item.time} + {item.tag} + + {item.desc} + )} + + {(list.length > 2) && changeMore()}> + {showMore&&'收起详情'||'点击查看详情'} + + } + + + } - - - - + ) }) \ No newline at end of file diff --git a/src/pages/order/components/payment/index.tsx b/src/pages/order/components/payment/index.tsx index 4e6e223..65e5c71 100644 --- a/src/pages/order/components/payment/index.tsx +++ b/src/pages/order/components/payment/index.tsx @@ -82,7 +82,7 @@ export default memo(({show = false, onClose}:Param) => { - + diff --git a/src/pages/order/components/scanPay/index.tsx b/src/pages/order/components/scanPay/index.tsx index cd55c85..8467da4 100644 --- a/src/pages/order/components/scanPay/index.tsx +++ b/src/pages/order/components/scanPay/index.tsx @@ -1,24 +1,96 @@ import { Image, ScrollView, Text, View } from "@tarojs/components"; -import { memo } from "react"; -import AmountShow from "../amountShow"; +import { memo, useEffect } from "react"; import classnames from "classnames"; import styles from './index.module.scss' - -import MCheckbox from "@/components/checkbox"; import Popup from "@/components/popup"; -import SearchInput from "@/components/searchInput"; import Taro from "@tarojs/taro"; +import { alert } from "@/common/common"; import { formatImgUrl } from "@/common/fotmat"; +import useCheckAuthorize from "@/use/useCheckAuthorize"; +import { GetPayCode } from "@/api/onlinePay"; + type Param = { show?: true|false, onClose?: () => void } export default memo(({show = true, onClose}:Param) => { + const base64 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQAQMAAAC6caSPAAAABlBMVEX///8AAABVwtN+AAACFElEQVR42uyaMbKzMAyExVC8kiNwFI5GjsZRcgRKCgb9I69sY+Ik7R+8O/OKF/N1Gnklr1AURVEURf2sBnUd+P9PZdxFpFddRaZ4uhEhAiR+euBznM2q+hCRacXpROSuiJ0vjphG1YfVkRXM2lm5ECFSR/QpYn+hw+hBhMgnRCScCxA0JSJE3t1i4XdrTPa5e5gvFx+R9pBseqdN9AnTO6+9Pobjq08m8ttIKUP02ZdT0GcRaQuxDhOKyWvMTK/VmMi8droMBxEiNUw6Xawhaagxm5LipGRe+KUpEWkVifMz2hDOXcHwHqV/IdI6IvH3U41JaEqhV6HGLhiRuyBhRj7yyIMrKXnhNYw7L0t7Is0i0mF7snW5w+xp17/4w8+1wxBpF4G79ZEIhbWn2yqY3ortIdIu0mHhYrcYxuqwhRvwkhi88HULR6R5xBd3mmwPmlIaqdGciBBJyKmQjEeNddH2VGuMyO8jeaGCeyfnlAzxLVwlp0SkUeTsbv0dedxlNh8TN7qVRyEizSJlFg4exn7Oo/Xy9zEJSaQt5KS0hzmnaWuml0jDSJm1LqakwbNw28X0ErkPUuaUxg0F40mV+FooRIjUs9Y4n31S8ljTS40RIYLgW1yoxAQkPMzbtC2RlpF0i0mekrwpESFSn5IUq9vYkJba2pbIfZBT1trfkUNSpc/BNiJEKIqiKIqi/gv9CwAA//9IKiY1VjApygAAAABJRU5ErkJggg==' + + + + const {check} = useCheckAuthorize({scope:'scope.writePhotosAlbum', msg:'您没授权,无法保存图片'}) + const saveImageCheck = async () => { + const res = await check() + res&&saveImage() + } + //保存图片 + const saveImage = () => { + const save = Taro.getFileSystemManager() + const number = Math.random(); + const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64) || []; + let filePath = Taro.env.USER_DATA_PATH +'/pic.'+ format + alert.loading('正在保存图片') + save.writeFile({ + filePath: filePath, + data: base64, + encoding: 'base64', + success: function (res) { + console.log('aa::',res) + console.log('aa2::',filePath) + Taro.saveImageToPhotosAlbum({ + filePath: filePath, + success: function (res) { + alert.success('图片保存成功') + }, + fail: function (err) { + console.log('err::', err) + } + }) + } + }) + } + //预览图片 + const showImage = () => { + Taro.previewImage({ + current: formatImgUrl(''), // 当前显示图片的http链接 + urls: [formatImgUrl('')] // 需要预览的图片http链接列表 + }) + } + + // const {fetchData} = GetPayCode() + // useEffect(() => { + // fetchData({ + // title: "面料销售电子确认单", + // company: "什么什么公司123", + // order_type: "散剪", + // sale_user: "小崔", + // order_created_time:"2022/02/01 12:32:13", + // order_no:"XS-211005888", + // department:"嘻嘻嘻", + // shipment_mode:"自提", + // target_user_name:"大崔", + // target_address:"阿斯顿发斯蒂芬", + // target_description:"无", + // pay_account:"1234567890123450001", + // bank_account_name:"佛山市浩川长盛科技有限公司", + // bank_name:"招商银行佛山分行禅城支行", + // pay_type:"现结", + // client:"客户名称", + // phone:"15818085802", + // order_total_length:"12", + // order_total_price:"23000", + // qrcode:"www.zzfzyc.com/checkorder/XS-211005888", + // order_total_weight:"300.00", + // list: [{product_code:'5215',product_name:'26S双纱亲水滑爽棉',product_color_code:'053',product_color_name:'洋红',num:'4',weight:'123.23',sale_price:'43',total_price:'4510.7'}] + // }) + // }, []) + + //复制功能 return ( - + 扫码支付 @@ -27,9 +99,9 @@ export default memo(({show = true, onClose}:Param) => { 扫码支付成功后,自动更新状态 - + - {}}>保存电子确认单 + 保存电子确认单 diff --git a/src/pages/order/index.tsx b/src/pages/order/index.tsx index 5a3f8d5..47259cd 100644 --- a/src/pages/order/index.tsx +++ b/src/pages/order/index.tsx @@ -9,6 +9,7 @@ import Taro, { useDidShow, useRouter } from "@tarojs/taro"; import classnames from "classnames"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import AddressInfo from "./components/addressInfo"; +import AddressInfoDetail from "./components/addressInfoDetail"; import KindList from "./components/kindList"; import OrderState from "./components/orderState"; import Payment from "./components/payment"; @@ -46,36 +47,19 @@ import styles from './index.module.scss' //格式化数据格式 const [formatDetailOrder, setFormatDetailOrder] = useState() //格式化后的数据 const formatData = () => { - if(orderDetail?.color_list&&orderDetail?.color_list.length > 0) { - let dataList = {} - let num_count = 0 //总数量 - orderDetail?.color_list.map(item => { - dataList[item.product_code] = dataList[item.product_code]||{} - dataList[item.product_code].product_code = item.product_code - dataList[item.product_code].product_name = item.product_name - dataList[item.product_code].sale_mode_name = orderDetail.sale_mode_name - dataList[item.product_code].color_list = dataList[item.product_code]?.color_list||[] - dataList[item.product_code].color_list.push(item) - //大货 - if (orderDetail.sale_mode == 0) num_count += item.roll - //剪板或散件 - if (orderDetail.sale_mode == 1 || orderDetail.sale_mode == 2) num_count += item.length - }) - if (orderDetail.sale_mode == 1 || orderDetail.sale_mode == 2) num_count = Number(num_count / 100); - setFormatDetailOrder({ - estimate_amount: orderDetail.estimate_amount, //预估金额 - estimate_weight: orderDetail.estimate_weight, - sale_mode: orderDetail.sale_mode, - sale_mode_name: orderDetail.sale_mode_name, - colo_count: orderDetail.color_list.length, //颜色数量 - num_count: num_count, //总数量 - unit: orderDetail.sale_mode == 0?'条':'m', //单位 - list: Object.values(dataList) - }) - } + setFormatDetailOrder({ + estimate_amount: orderDetail.estimate_amount, //预估金额 + sale_mode: orderDetail.sale_mode, + sale_mode_name: orderDetail.sale_mode_name, + total_colors: orderDetail.total_colors, //总颜色数量 + total_number: orderDetail.total_number, //总数量 + total_fabrics: orderDetail.total_fabrics, //面料数量 + unit: orderDetail.sale_mode == 0?'条':'m', //单位 + list: orderDetail.product_list + }) } - const formatPreViewOrderMemo = useMemo(() => { + console.log('formatDetailOrder::',formatDetailOrder) return formatDetailOrder }, [formatDetailOrder]) @@ -120,23 +104,6 @@ import styles from './index.module.scss' setShowDesc(() => false) }, []) - //修改地址 - const changeAddress = () => { - //临时传递数据 - setParam({ - province_name: orderDetail?.province_name, - city_name: orderDetail?.city_name, - district_name: orderDetail?.district_name, - address_detail: orderDetail?.address_detail, - id: orderId.current, - name: orderDetail?.target_user_name, - phone: orderDetail?.target_user_phone, - shipment_mode: orderDetail?.shipment_mode, - } - ) - goLink('/pages/editOrder/index') - } - //去付款 const [payMentShow, setPayMentShow] = useState(false) const toPay = () => { @@ -144,26 +111,26 @@ import styles from './index.module.scss' } return ( - + {/* - - - changeAddress()}> - + */} + + + 订单信息 - + {orderDetail?.order_no} clipboardData()}>复制 - + {formatDateTime(orderDetail?.create_time)} - + {formatDateTime(orderDetail?.create_time)} diff --git a/src/styles/iconfont.scss b/src/styles/iconfont.scss index 246e5e5..291d27f 100644 --- a/src/styles/iconfont.scss +++ b/src/styles/iconfont.scss @@ -1,6 +1,6 @@ @font-face { font-family: "iconfont"; /* Project id 2987621 */ - src: url('iconfont.ttf?t=1652868058352') format('truetype'); + src: url('iconfont.ttf?t=1653384789393') format('truetype'); } .iconfont { @@ -11,6 +11,26 @@ -moz-osx-font-smoothing: grayscale; } +.icon-yucunkuan:before { + content: "\e66c"; +} + +.icon-xianxiahuikuan:before { + content: "\e669"; +} + +.icon-xtianzhangqi:before { + content: "\e66a"; +} + +.icon-saomazhifu:before { + content: "\e66b"; +} + +.icon-fahuo:before { + content: "\e66d"; +} + .icon-zhuyi:before { content: "\e668"; } diff --git a/src/styles/iconfont.ttf b/src/styles/iconfont.ttf index 7167c2af488d962281b74576a2c8465a58eaa670..65bed9ce356493a9a3134d4706a948a357404b39 100644 GIT binary patch delta 2211 zcmZWpU2GIp6h3#hJ2N}mooV;4P+;5c!fvg`4^Ir_zrS#G8tYTAb7T3bBdm*l!2B}Uwd47* zp^6VXz94FB!8;2_CXRZJ4Oad;OVo4@4%b_kB3*G}hy|)EJY5H@jyvQogM;YTxm`am zJr@@j?K0+g1-4F#@Zu8d;`1R^!DfogKeJZJH_nxuM4ywRG)mxUAaah%=w*cKayj3| z$7a4#R%Ca;w~UrkHLakPw2DGhL$y>#0SZ%uf>cGTX$?imq;j&Tf-1>NKJt@?+}Kwq z7ipv-AqVzn|DswR%65J3IJ z_eg*V;(H~)3Grtozz*?!65xsWb7YGffimKK5+INGehJV>{D1@qCEhOqYKiA1Kr-=z z5}=#-fCPvqJ}4oigZQunxoivy5>SZvhy=7EJ}M#Fh(9j@{fHlufRe-yONbug zV-ir8Zb2FW=uEdDjewB2boJ9U*1|3-+mz27c7x-mvWw1I=Yo1c+oa9u+x72UEv_kJ z%J{_{a=%%=rTksbO3$li(A;jmXr3{zS%cP>*3F7g#X_a-^?Os^oa}SQka7bYZAKG^ zO~oHllATIA6^q8AzGTp^HnKq5y{BIdN7u7RIGW0=vsqdWSPW*ehP7u9Wif?qJvo@k z44yoFYM{Nfxp!xoVOd5`wYXPXeoGE|4AV3kJ2cC$XLGvW(mIqInZZ-1r-#JSt@-SZ z=GNjBgs04anG$PD131Ql8%x)bpbXy`Spkj)tta#;s|&AXnJy+XDrK)pPbuZL zx@3r{7E{|D$*N#g(66bQ8Wsg-+Qsi77L>P(*IgBQnHJLmrslfiHqB1WV>=yA*FPdN zR%^)Fs@JmJo8!1PcYlOI0~4d{Lv*n7Zm&;`=~h6~QO-Htw45#!DZOp%rKRQf_lYMT zW=7O(qlrqD{{ihHl%@>Pn($gB)u|*yN}yDeLo?Yb=C2AS+cWD~DjL(m&Fp__sj)}& z+W%T$`8(yI^7GaHH#|m@W(KryRts2q-c`M_ec+x(({^`%wzs)eX>Cv=fyupnn%1{> zG7wR38%;u?x*V$0`;De0iJnw06$VwfCDd80T zCPGVAP%fy8gl*A;EGg=eQ>qWkQyGYhroC!diBLhPQ!q?R*<)Cy8za*w)FiB8q7X`e zdsv8IXXJ$2ge&2@`<_^(9K>BAELw_$>S6~G6DqjPqMa!{mz;9DQcx(tT4CZZ6v9UX zGTF+X_(rZl{f~ix9&ms&&%!Yl4QmXiD%Fl=tzsc&GSqgT8c~0&EgkVa>a!!xN1c%> zaFDJPj07tEL2!||Z>f$Uw^saG^XuYfX>3EVGr%^e4%JiKx5wl2dBiQ7N^N=2V3oVY z)Na%3&85@R#o?MpG%K2Z|9MFUD`;$^rWF^&S!Rz1gT-%D%hbhgUa#0PnJQkv2Blp* zzSi{cgT{}E5F{S8ha!|McL%H+SaDxpU6>&y+{L50v&6UwnJl z0XR1R&rmjhZPJ~;eH!qmfMjECA~T*Wq!$6y$i5s6fv=u2*GnXon<~tfocdqD{NTQn zpB~GUm*+nNzE9luPGx3iOb1qY-o$z}}`hjd!G zyVQ0d1w&s_eNtNTOq`E>aWr(xw-dFbKfD_HlPt3u?d^ege^#*8Cwy@Hndi zD$E0NRAEMtK83kKjw#F%a$I4)kP`|shZIk8A}j*Zudp1*DTReW1{9VEVdpI@7BZ-? zY{(gf0zl3xlmc>2p(qgc#zJ`@7nCBEf($8Edl^=!9^|58HIfm9ib6&eY75CIR2gzf zq27=&g~~(574`r!p|Bf}Nfhk_HU^Sa>|2qXVjsmS<+ZSFSf#uc+a``t)XXhs-1+D! zcn7_|eL275zwVbnd$2utCs=LhYWNfC4}A!ChTle^>3!9=^- diff --git a/src/use/useCheckAuthorize.tsx b/src/use/useCheckAuthorize.tsx new file mode 100644 index 0000000..05ae81f --- /dev/null +++ b/src/use/useCheckAuthorize.tsx @@ -0,0 +1,51 @@ +import { alert } from "@/common/common"; +import Taro from "@tarojs/taro"; +import { memo, useCallback, useState } from "react"; + +type Scope = 'scope.userLocation'|'scope.userLocation'|'scope.record'|'scope.camera'|'scope.bluetooth'|'scope.writePhotosAlbum'|'scope.addPhoneContact'|'scope.addPhoneCalendar'|'scope.werun'|'scope.address'|'scope.invoiceTitle'|'scope.invoice'|'scope.userInfo' +type Param = { + scope: Scope, + msg: string //检查不通过时警告 +} +export default ({scope, msg}: Param) => { + //检查授权 + const check = useCallback(() => { + return new Promise((reslove, reject) => { + Taro.getSetting({ + success: (res) => { + if(res.authSetting[scope]) { + reslove(true) + } else if (res.authSetting[scope] === undefined) { + Taro.authorize({ + scope: scope, + success() { + reslove(true) + }, + fail() { + alert.none(msg) + reject(false) + } + }) + } else { + Taro.openSetting({ + success(res) { + if(res.authSetting[scope]) { + reslove(true) + } else { + alert.none(msg) + reject(false) + } + } + }) + } + } + }) + }) + + }, [scope]) + + return { + check, + } + +} \ No newline at end of file diff --git a/src/use/useHttp.ts b/src/use/useHttp.ts index 05b143b..592321f 100644 --- a/src/use/useHttp.ts +++ b/src/use/useHttp.ts @@ -32,7 +32,8 @@ type option = { data?: any, page?: number, pageSize?: number, - pagination?: true|false + pagination?: true|false, + base_url?: string } /** @@ -99,9 +100,9 @@ export const useRequest = (options:option = { page: 1, pageSize: 24, pagination: false, // 是否分页 + base_url: '' }) => { - - options.url = `${BASE_URL}${options.url}` + options.url = `${options.base_url||BASE_URL}${options.url}` let params:Params = { code: null, // 业务码 success: false, // 请求是否成功 @@ -121,7 +122,6 @@ export const useRequest = (options:option = { const stateRef = useRef({...params}) const [state, setState] = useState({...stateRef.current}) const {removeToken, removeSessionKey} = useUserInfo() - const router = useRouter() // 请求函数 const fetchData = async (sub_options?:any) => { stateRef.current.loading = true