123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- class Phone {
- //设备是否为android
- isAndroid() {
- console.log("成功进入isAndroid这个方法")
- var u = navigator.userAgent;
- if (u.indexOf('Android') > -1 || u.indexOf('Adr') > -1) {
- return true;
- }
- return false;
- }
- // 判断设备为 ios
- isIos() {
- console.log("成功进入isIos这个方法")
- var u = navigator.userAgent;
- if (u.indexOf("iPhone") > -1 || u.indexOf("iOS") > -1) {
- return true;
- }
- return false;
- }
- //获取设备的类型
- getSysType(): string {
- if (this.isAndroid()) {
- return "android"
- }
- if (this.isIos()) {
- return "ios"
- }
- return "web"
- }
- displayRow() {
- if (this.isIos()) {
- try {
- //@ts-ignore
- window.webkit.messageHandlers.displayRow.postMessage('displayRow')
- } catch (error) {
- console.log(error)
- }
- } else if (this.isAndroid()) {
- //@ts-ignore
- window.android && window.android.displayRow()
- }
- }
- displayCol() {
- if (this.isIos()) {
- try {
- //@ts-ignore
- window.webkit.messageHandlers.displayRow.postMessage('displayCol')
- } catch (error) {
- console.log(error)
- }
- } else if (this.isAndroid()) {
- //@ts-ignore
- window.android && window.android.displayCol()
- }
- }
- backView() {
- if (this.isIos()) {
- try {
- //@ts-ignore
- window.webkit.messageHandlers.backView.postMessage('backView')
- } catch (error) {
- console.log(error)
- }
- } else if (this.isAndroid()) {
- try {
- // alert('运行前')
- // console.log('运行前')
- // console.log(typeof window.android.backView)
- //@ts-ignore
- window.WebViewJavascriptBridge && window.WebViewJavascriptBridge.callHandler(
- 'backView'
- , { 'param': '返回的方法' }
- , function () {
- }
- );
- //@ts-ignore
- window.android && window.android.backView()
- // alert('运行后')
- } catch (error) {
- console.log(error)
- }
- }
- }
- //ios 内购的方法
- ipyCallgo() {
- if (this.isIos()) {
- try {
- //@ts-ignore eslint-disable-next-line
- window.webkit.messageHandlers.ipyCallgo.postMessage('ipyCallgo')
- //@ts-ignore
- document.getElementById('msg').textContent = '成功调用ipyCallgo'
- } catch (error) {
- if(document.getElementById('msg')){
- //@ts-ignore
- document.getElementById('msg').textContent = JSON.stringify(error)
- }
- console.error(error);
- }
- }
- }
- //微信购买的方法
- spyCallgo(universalLink: string) {
- if (this.isIos()) {
- try {
- //@ts-ignore
- window.webkit.messageHandlers.spyCallgo.postMessage(universalLink)
- } catch (error) {
-
-
- console.log(error)
- }
- }
- }
- //下单的接口错误
- errCallgo(code: string) {
- if (this.isIos()) {
- try {
- //@ts-ignore
- window.webkit.messageHandlers.errCallgo.postMessage(code)
- } catch (error) {
- console.log(error)
- }
- }
- }
- ladCallgo(){
- if (this.isIos()) {
- try {
- //@ts-ignore
- window.webkit.messageHandlers.ladCallgo.postMessage('n://wap/pay?')
- } catch (error) {
- console.log(error)
- }
- }
- }
- }
- export default Phone
|