diff --git a/Laravel/app/Http/Controllers/API/UpLoadController.php b/Laravel/app/Http/Controllers/API/UpLoadController.php index 8f56ae4..3aa8535 100644 --- a/Laravel/app/Http/Controllers/API/UpLoadController.php +++ b/Laravel/app/Http/Controllers/API/UpLoadController.php @@ -3,9 +3,11 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; +use Illuminate\Support\Facades\Log; use App\Services\Admin\YeWu\HealthCheckupService; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Storage; class UpLoadController extends Controller { @@ -19,12 +21,20 @@ class UpLoadController extends Controller $save = $file->store('public/H5Upload/'.$date); return \Yz::Return(true,'上传成功',$save); - - - - }else{ return \Yz::echoError1('获取文件失败'); } } + public function UpFileBase64() + { + $base64Image =request('base64file'); // 获取 base64 图片字符串 +// Log::info($base64Image); + // 将 base64 字符串转换为图片并保存 + $image = base64_decode(explode(',', $base64Image)[1]); + $date = date("Ymd"); + $filename = 'image_' . time() . '.png'; // 或者使用其他方式生成文件名 + Storage::disk('public')->put('/H5Upload/'.$date.'/'.$filename, $image); // 保存图片到 public 目录 + return \Yz::Return(true,'上传成功',['fileurl' =>'/storage/H5Upload/'.$date.'/'.$filename]); + + } } diff --git a/Laravel/app/Services/LogService.php b/Laravel/app/Services/LogService.php index 96c4ce4..1e3e58f 100644 --- a/Laravel/app/Services/LogService.php +++ b/Laravel/app/Services/LogService.php @@ -112,7 +112,13 @@ class LogService $str_len = mb_strlen(json_encode($post_datum, JSON_UNESCAPED_UNICODE)); $str_size = $str_len / 1024; if ($str_size > 10) { - $post_data->$key= 'Row size too large'; + if(is_array($post_data)){ + $post_data[$key]= 'Row size too large'; + }elseif(is_object($post_data)){ + $post_data->$key= 'Row size too large'; + }else{ + $post_data="data size too large"; + } } } $post_data = json_encode($post_data, JSON_UNESCAPED_UNICODE); diff --git a/Laravel/routes/api.php b/Laravel/routes/api.php index e9b1851..36ccf0a 100644 --- a/Laravel/routes/api.php +++ b/Laravel/routes/api.php @@ -66,6 +66,7 @@ Route::group(['middleware'=>['checktoken','log'],'prefix'=>'v1/mH5'],function () Route::post('GetEnableCalendar','App\Http\Controllers\API\mH5\OrganizationController@GetEnableCalendar'); //获取可用体检机构日历 Route::post('StartYuYue','App\Http\Controllers\API\mH5\OrganizationController@StartYuYue'); //开始预约 Route::post('UpFile','App\Http\Controllers\API\UpLoadController@UpFile'); //上传文件 + Route::post('UpFileBase64','App\Http\Controllers\API\UpLoadController@UpFileBase64');//上传文件base64 Route::post('GetPersonReportDetail','App\Http\Controllers\API\mH5\PersonController@GetPersonReportDetail');//获取用户pdf Route::post('GetIndustryList','App\Http\Controllers\API\mH5\IndustryController@GetIndustry'); }); diff --git a/mH5/src/api/api.js b/mH5/src/api/api.js index c63fdc0..c09d13c 100644 --- a/mH5/src/api/api.js +++ b/mH5/src/api/api.js @@ -29,6 +29,10 @@ export const StartYuYue = (data) => { export const UpFile = (data) => { return axios({url:import.meta.env.VITE_APP_API+'v1/mH5/UpFile',data:data}) } +//上传图片base64 +export const UpFileBase64 = (data) => { + return axios({url:import.meta.env.VITE_APP_API+'v1/mH5/UpFileBase64',data:data}) +} //获取体检报告详情 export const GetPersonReportDetail = (data) => { diff --git a/mH5/src/jsBridge/Bridge.js b/mH5/src/jsBridge/Bridge.js new file mode 100644 index 0000000..5f43064 --- /dev/null +++ b/mH5/src/jsBridge/Bridge.js @@ -0,0 +1,66 @@ +const isAndroid = navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Adr') > -1 +const isiOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) +// 这是必须要写的,用来创建一些设置 +function setupWebViewJavascriptBridge(callback) { + // Android使用 + if (isAndroid) { + if (window.WebViewJavascriptBridge) { + callback(window.WebViewJavascriptBridge) + } else { + document.addEventListener( + 'WebViewJavascriptBridgeReady', + () => { + callback(window.WebViewJavascriptBridge) + }, + false + ) + } + sessionStorage.phoneType = 'android' + } + // iOS使用 + if (isiOS) { + if (window.WebViewJavascriptBridge) { + return callback(window.WebViewJavascriptBridge) + } + if (window.WVJBCallbacks) { + return window.WVJBCallbacks.push(callback) + } + window.WVJBCallbacks = [callback] + var WVJBIframe = document.createElement('iframe') + WVJBIframe.style.display = 'none' + WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__' + document.documentElement.appendChild(WVJBIframe) + setTimeout(() => { + document.documentElement.removeChild(WVJBIframe) + }, 0) + sessionStorage.phoneType = 'ios' + } +} +// 注册回调函数,第一次连接时调用 初始化函数(android需要初始化,ios不用) +setupWebViewJavascriptBridge((bridge) => { + if (isAndroid) { + // 初始化 + bridge.init((message, responseCallback) => { + var data = { + 'Javascript Responds': 'Wee!' + } + responseCallback(data) + }) + } +}) +export default { + // js调APP方法 (参数分别为:app提供的方法名 传给app的数据 回调) + callHandler(name, data, callback) { + setupWebViewJavascriptBridge((bridge) => { + bridge.callHandler(name, JSON.stringify(data), callback) + }) + }, + // APP调js方法 (参数分别为:js提供的方法名 回调) + registerHandler(name, callback) { + setupWebViewJavascriptBridge((bridge) => { + bridge.registerHandler(name, (data, responseCallback) => { + callback(data, responseCallback) + }) + }) + } +} \ No newline at end of file diff --git a/mH5/src/jsBridge/JSBridge.js b/mH5/src/jsBridge/JSBridge.js new file mode 100644 index 0000000..3cf3eed --- /dev/null +++ b/mH5/src/jsBridge/JSBridge.js @@ -0,0 +1,216 @@ +(function(global) { + var task, img, styleTask, styleImg; + + function createLoading() { + task = document.createElement('div'); + task.style.cssText = 'position:fixed;background:rgba(0,0,0,0);left:0;top:0;width:100%;height:100%;z-index:9999'; + document.documentElement.appendChild(task); + }; + + function removeLoading() { + document.documentElement.removeChild(task); + task = null; + }; + + function JSBridge() { + this.name = 'JSBridge'; + this.reset = true; + }; + + JSBridge.prototype.device = function() { + var u = navigator.userAgent; + var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; + var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); + return isAndroid; + }; + /** + * @param null + * JSBridge初始化 + */ + JSBridge.prototype._init = function(callback) { + if (window.WebViewJavascriptBridge) { + return callback(WebViewJavascriptBridge); + } + if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); } + window.WVJBCallbacks = [callback]; + var WVJBIframe = document.createElement('iframe'); + WVJBIframe.style.display = 'none'; + WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__'; + document.documentElement.appendChild(WVJBIframe); + setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0) + }; + /** + * @param null + * JSBridge 安卓初始化回调接口 + */ + JSBridge.prototype.__init__ = function(bridge) { + var isAn = this.device(); + if (this.reset && isAn) { + this.reset = false; + bridge.init(function(message, responseCallback) { + console.log('JS got a message', message); + var data = { + 'Javascript Responds': '测试中文!' + }; + console.log('JS responding with', data); + responseCallback(data); + }); + } + }; + + + /* + * 调用原生方法 + */ + JSBridge.prototype.callHandler = function(funcName, data, callback) { + var isAn = this.device(); + var _this = this; + // _this._init(function (bridge) { + // _this.__init__(bridge); + // bridge.callHandler(funcName, JSON.stringify(data), function (response) { + // if (callback) + // callback(JSON.parse(response)); + // }) + // }.bind(this)) + if(isAn){ + if(window.WebViewJavascriptBridge){ + _this._init(function (bridge) { + _this.__init__(bridge); + bridge.callHandler(funcName, JSON.stringify(data), function (response) { + if (callback) + callback(JSON.parse(response)); + }) + }.bind(this)) + }else{ + document.addEventListener( + 'WebViewJavascriptBridgeReady' + , function() { + _this._init(function (bridge) { + _this.__init__(bridge); + bridge.callHandler(funcName, JSON.stringify(data), function (response) { + if (callback) + callback(JSON.parse(response)); + }) + }.bind(this)) + }, + false + ); + } + }else{ + _this._init(function (bridge) { + _this.__init__(bridge); + bridge.callHandler(funcName, JSON.stringify(data), function (response) { + if (callback) + callback(JSON.parse(response)); + }) + }.bind(this)) + } + }; + + + /* + * 注册方法 + */ + JSBridge.prototype.registerHandler = function(funcName,initFuc, params) { + var isAn = this.device(); + var _this = this; + //处理android WebViewJavascriptBridge延时问题 + if(isAn) { + if(window.WebViewJavascriptBridge){ + _this._init(function (bridge) { + _this.__init__(bridge); + bridge.registerHandler(funcName, function (data, callback) { + if (initFuc) { + if (data) { + initFuc(JSON.parse(data)); + } else { + initFuc(); + } + } + /* if(callback) + callback(JSON.parse(data))*/ + if (params) { + callback(JSON.stringify(params)); + } else { + callback(); + } + + }) + }.bind(this)) + }else{ + document.addEventListener('WebViewJavascriptBridgeReady', function() { + _this._init(function (bridge) { + _this.__init__(bridge); + bridge.registerHandler(funcName, function (data, callback) { + if (initFuc) { + if (data) { + initFuc(JSON.parse(data)); + } else { + initFuc(); + } + } + /* if(callback) + callback(JSON.parse(data))*/ + if (params) { + callback(JSON.stringify(params)); + } else { + callback(); + } + + }) + }.bind(this)) + }, false); + } + }else{ + _this._init(function (bridge) { + _this.__init__(bridge); + bridge.registerHandler(funcName, function (data, callback) { + if (initFuc) { + if (data) { + initFuc(JSON.parse(data)); + } else { + initFuc(); + } + } + /* if(callback) + callback(JSON.parse(data))*/ + if (params) { + callback(JSON.stringify(params)); + } else { + callback(); + } + + }) + }.bind(this)) + } + }; + + /* + * 获取经纬度 + */ + JSBridge.prototype.getJwd = function(callback, params) { + this._init(function(bridge) { + this.__init__(bridge); + bridge.callHandler( 'getJwd', JSON.stringify({}), function(response) { + var res = JSON.parse(response); + jwd = res["longitude"]+","+res["latitude"]; + params["userLocation"] = jwd; + if(callback) + callback(params); + }) + }.bind(this)) + }; + + /* + * 全局变量设置 + */ + if (typeof module !== 'undefined' && module.exports) { + module.exports = JSBridge; + } else if (typeof define === 'function' && (define.amd || define.cmd)) { + define(function() { + return JSBridge; + }); + } else { + global.JSBridge = JSBridge; + }; +})(this); \ No newline at end of file diff --git a/mH5/src/jsBridge/quick-utils.js b/mH5/src/jsBridge/quick-utils.js new file mode 100644 index 0000000..6936bf8 --- /dev/null +++ b/mH5/src/jsBridge/quick-utils.js @@ -0,0 +1,462 @@ +/**各种使用的工具函数 + * 目测会替换掉 + * quick-view.js里面的 + * QuickUrlUtils + * createOptions + * + * quick-easyuiUtils里面的 + * createTreeList + * */ + +function QuickUtils() { } + +QuickUtils.findByList = function (list, value, valueField) { + var item = null; + for (var i = 0; i < list.length; i++) { + var list_item = list[i]; + var v = list_item[valueField]; + if (v == value) { + item = list_item; + } else { + var children = list_item["children"]; + if (children && children.length > 0) { + item = QuickUtils.findByList(children, value, valueField); + if (!item) { + continue; + } else { + break; + } + } + } + } + return item; +} + +QuickUtils.createTreeList = function (config) { + var finalConfig = $.extend({}, QuickUtils.convertTreeListDefaultConfig, config); + var list = finalConfig["list"]; + var sjdm = finalConfig["sjdm"]; + var idField = finalConfig["idField"]; + var textField = finalConfig["textField"]; + var reldateField = finalConfig["reldateField"]; + var itemIDField = finalConfig["itemIDField"]; + var itemTextField = finalConfig["itemTextField"]; + return QuickUtils.innerCreateTreeList(list, sjdm, idField, textField, reldateField, itemIDField, itemTextField); +} + +QuickUtils.innerCreateTreeList = function (list, sjjgdm, idField, textField, reldateField, itemIDField, itemTextField) { + var childList = []; + for (var i = 0; i < list.length; i++) { + var item = list[i]; + if (item == null) { + continue; + } + var sjjgdm1 = item[reldateField]; + if (sjjgdm1 != sjjgdm) { + continue; + } else { + var id = item[idField]; + item[itemTextField] = item[textField]; + item[itemIDField] = item[idField]; + var lt = QuickUtils.innerCreateTreeList(list, id, idField, textField, reldateField, itemIDField, itemTextField); + if (lt != null && lt.length != 0) { + item["children"] = lt; + } + childList.push(item); + list[i] = null; + } + } + if (childList.length == 0) { + childList = null; + } + return childList; +} + +QuickUtils.convertTreeListDefaultConfig = { + /*上级代码值*/ + sjdm: "" + /*ID字段*/ + , idField: "XMDM" + /*text字段*/ + , textField: "XMMC" + /*关联字段*/ + , reldateField: "SJDM" + /*item的id字段*/ + , itemIDField: "id" + /*item的text字段*/ + , itemIDField: "text" +}; + +/**URL工具类*/ +(function ($) { + var host = window.location.host; + var pathName = window.document.location.pathname.replace(/\/\//g, "/"); + var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1); + var currPagePath = pathName.substring(0, pathName.substr(1).lastIndexOf('/') + 1) + $.QuickUrlUtils = { + redirectUrl: function (url) { + location = currPagePath + "/" + url; + }, + redirectRootUrl: function (url) { + location = projectName + "/" + url; + } + , getProjectName: function () { + + return projectName; + } + , geCurrPagePath: function () { + return currPagePath; + } + , getHost: function () { + return host; + } + , getHostProject: function () { + return host + projectName; + } + , forward: function (url, title, subTitle, isClose) { + StoreCache.setCache("title", title); + if ($.QuickVersion["isWeb"]) { + location = url; + } + else if ($.QuickVersion["isWeixin"]) { + location = url; + } + else if ($.QuickVersion["android"]) { + if (!isClose) isClose = "2"; + var tzurl = currPagePath + "/" + url; + if (url.indexOf("FJZLYD") != -1) { + tzurl = url; + } + android.toWebViewActivity(tzurl, title, "", isClose); + } + else if ($.QuickVersion["iPhone"]) { + window.webkit.messageHandlers.fjzlyd.postMessage({ functionName: "toWebViewActivity", parameter: { url: currPagePath + "/" + url, title: title, subTitle: "", isClose: isClose } }); + } + } + , forwardRootUrl: function (url, title, subTitle, isClose) { + if ($.QuickVersion["isWeb"]) { + location = projectName + "/" + url; + } + else if ($.QuickVersion["isWeixin"]) { + location = projectName + "/" + url; + } + else if ($.QuickVersion["android"]) { + if (!isClose) isClose = "2"; + android.closeAllWebView(projectName + "/" + url, title, "", isClose); + } + else if ($.QuickVersion["iPhone"]) { + window.webkit.messageHandlers.fjzlyd.postMessage({ functionName: "toWebViewActivity", parameter: { url: projectName + "/" + url, title: title, subTitle: "", isClose: isClose } }); + } + } + , forwardAny: function (url) { + location = url; + } + , openNewWindow: function (url, title) { + window.open(url); + } + //获取URL参数 + , getRequest: function (key) { + var url = decodeURI(location.search); //获取url中"?"符后的字串 + var theRequest = new Object(); + if (url.indexOf("?") != -1) { + var str = url.substring(url.indexOf("?") + 1, url.length); + strs = str.split("&"); + for (var i = 0; i < strs.length; i++) { + if (!StringUtils.isEmpty(strs[i])) + theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); + } + } + if (!key) + return theRequest; + else + return theRequest[key]; + } + //获取URL参数 + , getRequestByURL: function (url, key) { + var theRequest = new Object(); + if (url.indexOf("?") != -1) { + var str = url.substring(url.indexOf("?") + 1, url.length); + strs = str.split("&"); + for (var i = 0; i < strs.length; i++) { + theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); + } + } + if (key == "") + return theRequest; + else + return theRequest[key]; + } + /**退回上级页面*/ + , back: function () { + history.back(-1); + } + /**预留jsbriage统一页面跳转*/ + , redirectJSBridge: function (options, data) { + if ($.QuickVersion["isIOSApp"] || $.QuickVersion["isApp"]) { + //console.log('use app'); + var params = { + "type": "H5", + "toPage": options["url"], + "hasNavigation": "true", + "animate": options.animate == undefined ? "push" : options.animate, + "params": data != undefined ? data : {}, + "refreshUrl": options["refreshUrl"] + }; + + + JSBridge.prototype.callHandler("forward", params); + + //JSBridge.prototype.callHandler("gotoWebView", options); + } + else if ($.QuickVersion["isWeixin"] || $.QuickVersion["isWeb"]) { + console.log("进入判断了") + location.href = options["url"]; + //当出现登录超时时,记住当前地址,登录之后跳转到当前地址。登录页和注册页以及忘记密码页 不做登录之后跳转的地址保存 + // if(location.href && location.href.indexOf('login')<0){ + // if(location.href.indexOf("?")>0){ + // StoreCache.setCache("afterLoginUrl",location.href+"&afterLoginUrl=yes"); + // }else{ + // StoreCache.setCache("afterLoginUrl",location.href+"?afterLoginUrl=yes"); + // } + // }else{ + StoreCache.removeCache("afterLoginUrl"); + // } + } + else { + + location.href = options["url"]; + StoreCache.removeCache("afterLoginUrl"); + } + } + /**预留jsbriage统一页面返回*/ + , rebackJSBridge: function (options) { + if ($.QuickVersion["isWeixin"]) { + location = options["url"]; + } + else if ($.QuickVersion["isIOSApp"] || $.QuickVersion["isApp"]) { + // if(StringUtils.isEmpty(options["app_user_agent"])){ + // options["url"] = currPagePath + "/" + options["url"]; + // } + var params = { + "type": "H5", + "toPage": options["url"], + "hasNavigation": "true", + "animate": "pop", + }; + + JSBridge.prototype.callHandler("forward", params); + + //JSBridge.prototype.callHandler("backtoWebView", options); + } + else if ($.QuickVersion["isWeb"]) { + location = options["url"]; + } + else { + + } + } + /**预留jsbriage统一页面刷新*/ + , refreshJSBridge: function (options) { + if ($.QuickVersion["isIOSApp"] || $.QuickVersion["isApp"]) { + JSBridge.prototype.callHandler("refreshPage", options); + } + else if ($.QuickVersion["isWeb"] && options["url"]) { + location = options["url"]; + } + else { + } + } + //在不提供上一页地址,返回上一页并刷新 + , reBackAndRefreshJSBridge: function (url, topage) { + if ($.QuickVersion["isIOSApp"] || $.QuickVersion["isApp"]) { + var options = { + "type": "H5", + "toPage": topage ? topage : "", + "hasNavigation": "true", + "animate": "pop", + "refreshUrl": url ? url : "" + }; + JSBridge.prototype.callHandler("forward", options); + } + else { + if(url && url!='*'){ + location = url; + }else{ + history.back(-1); + } + } + } + } +})(jQuery); + +/**创建下拉框选项*/ +(function ($) { + var defaultConfig = { + needNull: "true" + , textField: "XMMC" + , valueField: "XMDM" + }; + $.fn.createOptions = function (ary, config) { + var finalConfig = $.extend({}, defaultConfig, config); + $(this).empty(); + var needNull = finalConfig["needNull"]; + var textField = finalConfig["textField"]; + var valueField = finalConfig["valueField"]; + + var opts = []; + + if (needNull == "true") { + var opt = $('