diff --git a/supervise-uniapp/App.vue b/supervise-uniapp/App.vue index fe1d2827..f073a238 100644 --- a/supervise-uniapp/App.vue +++ b/supervise-uniapp/App.vue @@ -1,29 +1,40 @@ + // 设置整个项目的背景色 + page { + height: 100%; + background-color: #f5f5f5; + } + + /* #endif */ + + @import '@/uni_modules/uview-ui/index.scss'; + @import '@/common/app.scss'; + + .example-info { + font-size: 14px; + color: #333; + padding: 10px; + } + \ No newline at end of file diff --git a/supervise-uniapp/common/config.js b/supervise-uniapp/common/config.js index 35359ada..3140f23d 100644 --- a/supervise-uniapp/common/config.js +++ b/supervise-uniapp/common/config.js @@ -6,7 +6,9 @@ * loginTimeoutPage = "/pages/login/index", // 登录超时或失效的情况下,跳转到的登录页面 */ module.exports = { - baseUrl: 'http://jianguan.yyundong.com/api', + // baseUrl: 'https://jianguan.yyundong.com/api', + baseUrl: 'https://supervise.yxtsoft.com/api', + // baseUrl: 'http://192.168.1.193:8112', tokenName: "Authorization", // 请求头中token的名字,与服务器端对应 loginTimeoutCode: "5001", // 登录超时或失效的情况下,服务器端返回的错误码 loginTimeoutPage: "/pages/login/index", // 登录超时或失效的情况下,跳转到的登录页面 diff --git a/supervise-uniapp/common/request.api.js b/supervise-uniapp/common/request.api.js index 6f7a6d4f..e45e49da 100644 --- a/supervise-uniapp/common/request.api.js +++ b/supervise-uniapp/common/request.api.js @@ -5,5 +5,53 @@ export default { sayhello: (params = {}) => request.get("/sayb", params), getSalesReport: (params = {}) => request.get("/system/reportCenter/getSalesReport", params), getGoodsOnWay: (params = {}) => request.get("/system/reportCenter/getGoodsOnWay", params), - getThresholdAnalysis: (params = {}) => request.get("/system/risk/getThresholdAnalysis", params) -} + getThresholdAnalysis: (params = {}) => request.get("/system/risk/getThresholdAnalysis", params), + + // 查看预警信息 + selectBusinessRiskInfo: (params = {}) => request.post("/wxmpapi/v1/businessData/selectBusinessRiskInfo", params), + + // 获取审核报告内容 + getReportInfo: (params = {}) => request.post("/reportwxmpapi/v1/csmcashreport/getCsmReportByComSid", params), + // 获取今日回款明细 + getCsmReportTodayByComSid: (params = {}) => request.post( + "/reportwxmpapi/v1/csmcashreportcashed/getCsmReportTodayByComSid", + params), + // 获取昨日销售报表 + getCsmReportYesterdayByComSid: (params = {}) => request.post( + "/reportwxmpapi/v1/csmcashreportsales/getCsmReportYesterdayByComSid", + params), + + // 库存汇总表 + getReportInventoryDayGather: (params = {}) => request.get( + "/reportwxmpapi/reportinventory/getReportInventoryDayGather/" + + params, + params), + // 仓库库存明细表 + getReportInventoryDayStore: (params = {}) => request.get( + "/reportwxmpapi/reportinventory/getReportInventoryDayStore/" + params, params), + // 烟草仓库库存明细表 + getReportInventoryDayToStore: (params = {}) => request.get( + "/reportwxmpapi/reportinventory/getReportInventoryDayToStore/" + params, params), + + + // 获取首页面数据 + getWorkData: (params = {}) => request.get("/portal/v1/flow/task/" + params, params), + + // 获取云仓列表 + storeHouseListPage: (params = {}) => request.post("/portal/v1/flow/storeHouseListPage", params), + // 获取云仓详情 + storeHouseDetail: (params = {}) => request.get("/portal/v1/flow/fetchDetailsBySid/" + params, params), + + // 获取我的项目 + getProjectByUserSid: (params = {}) => request.get("/crm/v1/projectinformation/getProjectByUserSid/" + params, + params), + + // 获取我的项目详情 + getProjectBySid: (params = {}) => request.get("/crm/v1/projectinformation/getProjectBySid/" + params, + params), + + // 获取我的项目-仓库详情 + getStorehouseBySid: (params = {}) => request.get("/crm/v1/projectinformation/getStorehouseBySid/" + params, + params), + +} \ No newline at end of file diff --git a/supervise-uniapp/components/UserItem/UserItem.vue b/supervise-uniapp/components/UserItem/UserItem.vue new file mode 100644 index 00000000..469b35c9 --- /dev/null +++ b/supervise-uniapp/components/UserItem/UserItem.vue @@ -0,0 +1,101 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/components/uni-section/uni-section.vue b/supervise-uniapp/components/uni-section/uni-section.vue deleted file mode 100644 index 1b636ff9..00000000 --- a/supervise-uniapp/components/uni-section/uni-section.vue +++ /dev/null @@ -1,141 +0,0 @@ - - - - diff --git a/supervise-uniapp/manifest.json b/supervise-uniapp/manifest.json index caafa80f..7ae2a7da 100644 --- a/supervise-uniapp/manifest.json +++ b/supervise-uniapp/manifest.json @@ -1,9 +1,9 @@ { - "name" : "uView UI", + "name" : "汇融云仓贷后", "appid" : "__UNI__DD73AA7", - "description" : "多平台快速开发的UI框架", - "versionName" : "1.0.0", - "versionCode" : 1, + "description" : "汇融银行监管平台", + "versionName" : "1.0.0.7", + "versionCode" : 1007, "transformPx" : false, "app-plus" : { "optimization" : { @@ -24,42 +24,56 @@ "nvueCompiler" : "uni-app", "compilerVersion" : 3, "modules" : { - "Webview-x5" : {} + "Webview-x5" : {}, + "Camera" : {}, + "Barcode" : {}, + "Contacts" : {}, + "Push" : {} }, "distribute" : { "android" : { "permissions" : [ - "", - "", - "", - "", - "", - "", + "", "", - "", + "", + "", "", + "", + "", "", - "", + "", + "", + "", "", + "", "", + "", + "", + "", "", - "", + "", + "", + "", "", - "", - "", - "", - "", - "", + "", "" ], - "abiFilters" : [ "armeabi-v7a", "arm64-v8a" ] + "abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ] }, "ios" : { "idfa" : false, "dSYMs" : false }, "sdkConfigs" : { - "ad" : {} + "ad" : {}, + "geolocation" : { + "amap" : { + "__platform__" : [ "android" ], + "appkey_ios" : "", + "appkey_android" : "" + } + }, + "push" : {} }, "icons" : { "android" : { @@ -92,12 +106,15 @@ "spotlight@3x" : "unpackage/res/icons/120x120.png" } } + }, + "splashscreen" : { + "iosStyle" : "common" } } }, "quickapp" : {}, "mp-weixin" : { - "appid" : "", + "appid" : "wx65c2b78fd1452eeb", "setting" : { "urlCheck" : false, "es6" : false, @@ -107,7 +124,8 @@ "optimization" : { "subPackages" : true }, - "usingComponents" : true + "usingComponents" : true, + "lazyCodeLoading" : "requiredComponents" }, "mp-alipay" : { "usingComponents" : true, diff --git a/supervise-uniapp/pages.json b/supervise-uniapp/pages.json index 483450cc..69c6b32f 100644 --- a/supervise-uniapp/pages.json +++ b/supervise-uniapp/pages.json @@ -9,25 +9,94 @@ // }, "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages { + "path": "pages/index/demoReportKc", + "style": { + "navigationBarTitleText": "质物库存汇总" + } + },{ "path": "pages/login/login", "style": { - "navigationBarTitleText": "登录", - "enablePullDownRefresh": false + "navigationStyle": "custom", + "app-plus": { + "scrollIndicator": false //禁用原生导航栏, + } } - }, - { - "path": "pages/home/FindFragment", - "style": {} + }, { + "path": "pages/index/MyProject", + "style": { + "navigationBarTitleText": "我的项目" + } + + }, { + "path": "pages/index/ProjectDetail", + "style": { + "navigationBarTitleText": "项目详情" + } + + }, { + "path": "pages/index/WarehouseDetaile", + "style": { + "navigationBarTitleText": "云仓详情" + } + }, { "path": "pages/home/UserFragment", - "style": {} - },{ - "path": "pages/index/index", "style": { - "navigationBarTitleText": "APP示例" + "navigationBarTitleText": "个人中心" + + } + }, { + "path": "pages/home/WorkFragment", + "style": { + "navigationBarTitleText": "工作台" + } + }, { + "path": "pages/index/WarehouseManagement", + "style": { + "navigationBarTitleText": "云仓管理" + } + }, + { + "path": "pages/home/MessageFragment", + "style": { + "navigationBarTitleText": "消息" + } + }, { + "path": "pages/index/WarehouseList", + "style": { + "navigationBarTitleText": "云仓列表", + "enablePullDownRefresh": true + } + }, { + "path": "pages/index/WarehouseRegistration", + "style": { + "navigationBarTitleText": "云仓登记" + } + + }, { + "path": "pages/login/fwxy", + "style": { + "navigationBarTitleText": "服务协议" + } + }, { + "path": "pages/login/yszc", + "style": { + "navigationBarTitleText": "隐私政策" + } + }, + { + "path": "pages/index/auditReport", + "style": { + "navigationBarTitleText": "回款报告" + } + }, { + "path": "pages/index/enterpriseRisk", + "style": { + "navigationBarTitleText": "企业经营异常核查" } } ], + "lazyCodeLoading": "requiredComponents", "globalStyle": { "pageOrientation": "portrait", "navigationBarTitleText": "Hello uniapp", @@ -44,29 +113,30 @@ "navigationBarTextStyle": "black", "navigationBarBackgroundColor": "#F1F1F1" } - + }, "tabBar": { "color": "#959595", "selectedColor": "#41adf8", "backgroundColor": "#FFFFFF", "borderStyle": "black", + "iconWidth": "20px", // 字体大小 "list": [{ - "pagePath": "pages/home/FindFragment", - "iconPath": "static/bottom-icon/find_normal.png", - "selectedIconPath": "static/bottom-icon/find_press.png", + "pagePath": "pages/home/WorkFragment", + "iconPath": "static/bottom-icon/gongzuotai1.png", + "selectedIconPath": "static/bottom-icon/gongzuotai.png", "text": "工作台" }, { - "pagePath": "pages/home/AddFragment", - "iconPath": "static/bottom-icon/add_normal.png", - "selectedIconPath": "static/bottom-icon/add_press.png", + "pagePath": "pages/home/MessageFragment", + "iconPath": "static/bottom-icon/xiaoxi1.png", + "selectedIconPath": "static/bottom-icon/xiaoxi.png", "text": "消息" }, { "pagePath": "pages/home/UserFragment", - "iconPath": "static/bottom-icon/mine_normal.png", - "selectedIconPath": "static/bottom-icon/mine_press.png", + "iconPath": "static/bottom-icon/wode1.png", + "selectedIconPath": "static/bottom-icon/wode.png", "text": "我的" }] - + } -} +} \ No newline at end of file diff --git a/supervise-uniapp/pages/home/FindFragment.vue b/supervise-uniapp/pages/deprecated/MessageFragment.vue similarity index 100% rename from supervise-uniapp/pages/home/FindFragment.vue rename to supervise-uniapp/pages/deprecated/MessageFragment.vue diff --git a/supervise-uniapp/pages/deprecated/UserFragment.vue b/supervise-uniapp/pages/deprecated/UserFragment.vue new file mode 100644 index 00000000..a69f3ac5 --- /dev/null +++ b/supervise-uniapp/pages/deprecated/UserFragment.vue @@ -0,0 +1,220 @@ + + + + + diff --git a/supervise-uniapp/pages/home/AddFragment.vue b/supervise-uniapp/pages/deprecated/WorkFragment.vue similarity index 100% rename from supervise-uniapp/pages/home/AddFragment.vue rename to supervise-uniapp/pages/deprecated/WorkFragment.vue diff --git a/supervise-uniapp/pages/home/MessageFragment.vue b/supervise-uniapp/pages/home/MessageFragment.vue new file mode 100644 index 00000000..88ca6326 --- /dev/null +++ b/supervise-uniapp/pages/home/MessageFragment.vue @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/pages/home/UserFragment.vue b/supervise-uniapp/pages/home/UserFragment.vue index a69f3ac5..785627fd 100644 --- a/supervise-uniapp/pages/home/UserFragment.vue +++ b/supervise-uniapp/pages/home/UserFragment.vue @@ -1,220 +1,151 @@ - + \ No newline at end of file diff --git a/supervise-uniapp/pages/home/WorkFragment.vue b/supervise-uniapp/pages/home/WorkFragment.vue new file mode 100644 index 00000000..5d922d1b --- /dev/null +++ b/supervise-uniapp/pages/home/WorkFragment.vue @@ -0,0 +1,544 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/pages/index/MyProject.vue b/supervise-uniapp/pages/index/MyProject.vue new file mode 100644 index 00000000..f3779108 --- /dev/null +++ b/supervise-uniapp/pages/index/MyProject.vue @@ -0,0 +1,132 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/pages/index/ProjectDetail.vue b/supervise-uniapp/pages/index/ProjectDetail.vue new file mode 100644 index 00000000..06c47e19 --- /dev/null +++ b/supervise-uniapp/pages/index/ProjectDetail.vue @@ -0,0 +1,265 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/pages/index/WarehouseDetaile.vue b/supervise-uniapp/pages/index/WarehouseDetaile.vue new file mode 100644 index 00000000..c7b8a168 --- /dev/null +++ b/supervise-uniapp/pages/index/WarehouseDetaile.vue @@ -0,0 +1,297 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/pages/index/WarehouseList.vue b/supervise-uniapp/pages/index/WarehouseList.vue new file mode 100644 index 00000000..2887adb3 --- /dev/null +++ b/supervise-uniapp/pages/index/WarehouseList.vue @@ -0,0 +1,283 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/pages/index/WarehouseManagement.vue b/supervise-uniapp/pages/index/WarehouseManagement.vue new file mode 100644 index 00000000..c4930c56 --- /dev/null +++ b/supervise-uniapp/pages/index/WarehouseManagement.vue @@ -0,0 +1,192 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/pages/index/WarehouseRegistration.vue b/supervise-uniapp/pages/index/WarehouseRegistration.vue new file mode 100644 index 00000000..8183fd03 --- /dev/null +++ b/supervise-uniapp/pages/index/WarehouseRegistration.vue @@ -0,0 +1,22 @@ + + + + + diff --git a/supervise-uniapp/pages/index/auditReport.vue b/supervise-uniapp/pages/index/auditReport.vue new file mode 100644 index 00000000..6acf7448 --- /dev/null +++ b/supervise-uniapp/pages/index/auditReport.vue @@ -0,0 +1,261 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/pages/index/demoReportKc.vue b/supervise-uniapp/pages/index/demoReportKc.vue new file mode 100644 index 00000000..5ce347ae --- /dev/null +++ b/supervise-uniapp/pages/index/demoReportKc.vue @@ -0,0 +1,349 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/pages/index/enterpriseRisk.vue b/supervise-uniapp/pages/index/enterpriseRisk.vue new file mode 100644 index 00000000..06df05b8 --- /dev/null +++ b/supervise-uniapp/pages/index/enterpriseRisk.vue @@ -0,0 +1,247 @@ + + + + + \ No newline at end of file diff --git a/supervise-uniapp/pages/index/index.vue b/supervise-uniapp/pages/index/index.vue deleted file mode 100644 index 4a24208c..00000000 --- a/supervise-uniapp/pages/index/index.vue +++ /dev/null @@ -1,61 +0,0 @@ - - - - - diff --git a/supervise-uniapp/pages/login/fwxy.vue b/supervise-uniapp/pages/login/fwxy.vue new file mode 100644 index 00000000..c2b23f34 --- /dev/null +++ b/supervise-uniapp/pages/login/fwxy.vue @@ -0,0 +1,1479 @@ + + + + + diff --git a/supervise-uniapp/pages/login/login.vue b/supervise-uniapp/pages/login/login.vue index 4277fee7..35c8b0a7 100644 --- a/supervise-uniapp/pages/login/login.vue +++ b/supervise-uniapp/pages/login/login.vue @@ -1,6 +1,6 @@ @@ -29,62 +122,322 @@ export default { data() { return { - avatar: '/static/uniui.png', - vavatar: '/static/uview/common/logo.png', + showPassword: true, + selectType:false, + rememberPsw: true, //复选框状态 默认勾选 + // avatar: '/static/uniui.png', + // vavatar: '/static/uview/common/logo.png', // 表单数据 formData: { - userName: 'admin', - password: '111111' - }, - rules: { - // 对name字段进行必填验证 - name: { - rules: [{ - required: true, - errorMessage: '账号不可以为空' - }] - }, - // 对passwd字段进行必填验证 - passwd: { - rules: [{ - required: true, - errorMessage: '密码不可以为空' - }] - } + userName: '', + password: '' }, + img1: "/static/loginIcon/notShow.png", + img2: "/static/loginIcon/wgx.png", + // rules: { + // // 对name字段进行必填验证 + // name: { + // rules: [{ + // required: true, + // errorMessage: '账号不可以为空' + // }] + // }, + // // 对passwd字段进行必填验证 + // passwd: { + // rules: [{ + // required: true, + // errorMessage: '密码不可以为空' + // }] + // } + // }, + } + }, + mounted() { + //取出缓存中的账号、密码 + const loginName = uni.getStorageSync('loginName'); + const loginPasword = uni.getStorageSync('loginPasword'); + console.log("缓存的账号:", loginName) + console.log("缓存的密码:", loginPasword) + //有账号、密码就赋值给文本,没有就清空 + if (loginName && loginPasword) { + this.formData.userName = loginName; + this.formData.password = loginPasword; } }, methods: { + nameInput(event) { + this.formData.userName = event.target.value + }, + paswordInput(event) { + this.formData.password = event.target.value; + }, + showPas(){ + this.showPassword=!this.showPassword + this.img1 = this.showPassword?"/static/loginIcon/notShow.png":"/static/loginIcon/isShow.png" + }, + selectClick(){ + this.selectType =!this.selectType + this.img2= this.selectType?"/static/loginIcon/xz.png":"/static/loginIcon/wgx.png" + }, + fwxy() { + uni.navigateTo({ + url: '/pages/login/fwxy' + }) + }, + yszc() { + uni.navigateTo({ + url: '/pages/login/yszc' + }) + }, + boxChange() { + this.rememberPsw = !this.rememberPsw; + console.log('rememberPsw:', this.rememberPsw) + }, dologin() { let _this = this - this.$refs.form - .validate() - .then(r => { - _this.$store - .dispatch('login', _this.formData) - .then(uinfo => { - console.log('MMMM:', uinfo) - getApp().globalData.username = uinfo.name - getApp().globalData.token = uinfo.token - console.log('gd--:', getApp().globalData) - // uni.redirectTo({ - // url: '/pages/index/index', - // }) - uni.switchTab({ - url: '../home/AddFragment' - }); - - }) - .catch(er => { - console.log('EEEE:', er) - }) - }) - .catch(err => { - console.log('eeee:', err) + if (this.auth()) { + this.$api.login(_this.formData).then((resp) => { + // if (resp.success) { + //勾选就缓存账号、密码 + if (_this.rememberPsw) { + console.log('rememberPsw1:', _this.rememberPsw) + uni.setStorageSync('loginName', this.formData.userName); + uni.setStorageSync('loginPasword', this.formData.password); + } else { //销毁缓存中的账号、密码 + console.log('rememberPsw2:', _this.rememberPsw) + uni.removeStorageSync('loginName'); + uni.removeStorageSync('loginPasword'); + } + + console.log('MMMM:', resp) + getApp().globalData = resp + // getApp().globalData.username = uinfo.name + // getApp().globalData.token = uinfo.token + // getApp().globalData.sid = uinfo.sid + // getApp().globalData.mobile = uinfo.mobile + // getApp().globalData.name = uinfo.name + // getApp().globalData.isAdmin = uinfo.isAdmin + // getApp().globalData.roleName = uinfo.roleName + // getApp().globalData.staffSid = uinfo.staffSid + console.log('gd--:', getApp().globalData) + // uni.redirectTo({ + // url: '/pages/index/index', + // }) + uni.switchTab({ + url: '/pages/home/WorkFragment' + }); + + }).catch(e => { + console.log('eeeee', e) }) - } + + // this.$refs.form + // .validate() + // .then(r => { + // _this.$store + // .dispatch('login', _this.formData) + // .then(uinfo => { + // console.log('MMMM:', uinfo) + // getApp().globalData = uinfo + // // getApp().globalData.username = uinfo.name + // // getApp().globalData.token = uinfo.token + // // getApp().globalData.sid = uinfo.sid + // // getApp().globalData.mobile = uinfo.mobile + // // getApp().globalData.name = uinfo.name + // // getApp().globalData.isAdmin = uinfo.isAdmin + // // getApp().globalData.roleName = uinfo.roleName + // // getApp().globalData.staffSid = uinfo.staffSid + // console.log('gd--:', getApp().globalData) + // // uni.redirectTo({ + // // url: '/pages/index/index', + // // }) + // uni.switchTab({ + // url: '/pages/home/WorkFragment' + // }); + + // }) + // .catch(er => { + // console.log('EEEE:', er) + // }) + // }) + // .catch(err => { + // console.log('eeee:', err) + // }) + } + + }, + //校验 + auth() { + if (this.formData.userName.length < 1 || this.formData.userName == '' && this.formData.password.length < + 1 || this.formData + .password == '') { + uni.showToast({ + icon: 'none', + title: '请输入用户名与密码' + }); + return false; + } + if (this.formData.userName.length < 1 || this.formData.userName == '') { + uni.showToast({ + icon: 'none', + title: '请输入用户名' + }); + return false; + } + if (this.formData.password.length < 1 || this.formData.password == '') { + uni.showToast({ + icon: 'none', + title: '请输入密码' + }); + return false; + } + + if(!this.selectType){ + uni.showToast({ + icon: 'none', + title: '请阅读并同意勾选"用户协议"和"隐私政策"' + }); + return false; + } + + return true; + }, + + forget() { + uni.showToast({ + icon: 'none', + title: '暂不支持' + }); + }, + weixin() { + uni.showToast({ + icon: 'none', + title: '暂不支持' + }); + }, + }, + } - + \ No newline at end of file diff --git a/supervise-uniapp/pages/login/yszc.vue b/supervise-uniapp/pages/login/yszc.vue new file mode 100644 index 00000000..60410ede --- /dev/null +++ b/supervise-uniapp/pages/login/yszc.vue @@ -0,0 +1,334 @@ + + + + + diff --git a/supervise-uniapp/plugins/APPUpdate/APPUpdate.md b/supervise-uniapp/plugins/APPUpdate/APPUpdate.md new file mode 100644 index 00000000..b6dbc1d4 --- /dev/null +++ b/supervise-uniapp/plugins/APPUpdate/APPUpdate.md @@ -0,0 +1,106 @@ +# APP版本更新、强制更新、漂亮的更新界面、IOS更新(跳转IOS store)、wgt更新 + +### QQ交流群(学习干货多多) 607391225 +![QQ交流群](http://qn.kemean.cn//upload/202004/14/15868301778472k7oubi6.png) + +### 常见问题 +1.安卓apk下载完成后没有更新APP? + +答:问题是因为没有添加APP安装应用的权限,解决方法在`manifest.json`文件里面`APP模块权限配置`的`Android打包权限配置`勾选以下权限 +``` + + +``` +若还有问题请看[安装apk无法执行的解决方案](https://ask.dcloud.net.cn/article/35703 "安装apk无法执行的解决方案") + +2.APP更新后版本号没变,还是之前的版本号? + +答:可能是更新的安装包没有升级版本号,`manifest.json`文件里面基本设置`应用版本号`和`应用版本名称`需要升高 + +3.APP更新后没有覆盖之前的APP? + +答:可能是更新的安装包`包名`和APP的`包名`不一样 + +### 第一步配置APP更新接口 +在`APPUpdate.js`里面`getServerNo`函数方法配置更新接口 +``` +let httpData = { + version:version +}; +if (platform == "android") { + httpData.type = 1101; +} else { + httpData.type = 1102; +} +/* 接口入参说明 + * version: 应用当前版本号(已自动获取) + * type:平台(1101是安卓,1102是IOS) + */ +$http.get("api/kemean/aid/app_version", httpData).then(res => { + /*接口出参说明 (res数据说明) + * | 参数名称 | 一定返回 | 类型 | 描述 + * | -------------|--------- | --------- | ------------- | + * | versionCode | y | int | 版本号 | + * | versionName | y | String | 版本名称 | + * | versionInfo | y | String | 版本信息 \n 换行(例如:1.修改了bug1 \n 2.修改了bug2 \n 3.修改了bug3) | + * | forceUpdate | y | boolean | 是否强制更新 | + * | downloadUrl | y | String | 版本下载链接 `IOS安装包更新请放跳转store应用商店链接,安卓apk和wgt文件放文件下载链接` | + */ +}); +``` + +### 第二步 使用方法 +``` +// App.vue页面 + +// #ifdef APP-PLUS +import APPUpdate from "@/plugins/APPUpdate"; +// #endif + +onLaunch: function(e) { + // #ifdef APP-PLUS + APPUpdate(); + // #endif +} +``` + +### 第三步 添加APP安装应用的权限 +在`manifest.json`文件里面`APP模块权限配置`的`Android打包权限配置`勾选以下权限 +``` + + +``` + +### 修改弹窗的主题色或弹窗图标 +在`APPUpdate.js`里面上面`$mainColor`常量中定义主题颜色,`$iconUrl`常量中定义图标地址 + +### 检查APP是否有新版本(一般在设置页面使用) +``` +// #ifdef APP-PLUS +import APPUpdate, { getCurrentNo } from "@/plugins/APPUpdate"; +// #endif +export default { + data() { + return { + version: "" // 版本号 + }; + }, + //第一次加载 + onLoad(e) { + // #ifdef APP-PLUS + getCurrentNo(res => { + // 进页面获取当前APP版本号(用于页面显示) + this.version = res.version; + }); + // #endif + }, + //方法 + methods: { + // 检查APP是否有新版本 + onAPPUpdate() { + // true 没有新版本的时候有提示,默认:false + APPUpdate(true); + } + } +} +``` \ No newline at end of file diff --git a/supervise-uniapp/plugins/APPUpdate/index.js b/supervise-uniapp/plugins/APPUpdate/index.js new file mode 100644 index 00000000..59bb3f58 --- /dev/null +++ b/supervise-uniapp/plugins/APPUpdate/index.js @@ -0,0 +1,829 @@ +// #ifdef APP-PLUS +// import $api from '@/common/api'; +import $http from '@/utils/requester.js'; +const platform = uni.getSystemInfoSync().platform; +// 主颜色 +const $mainColor = "FF5B78"; +// 弹窗图标url +const $iconUrl = "/static/ic_ar.png"; +// 获取当前应用的版本号 +export const getCurrentNo = function(callback) { + // 获取本地应用资源版本号 + console.log("》》》》", 11111111111111111); + plus.runtime.getProperty(plus.runtime.appid, function(inf) { + callback && callback({ + versionCode: inf.version.replace(/\./g, ""), + version: inf.version, + }); + }); +} +// 发起ajax请求获取服务端版本号 +export const getServerNo = function(version, isPrompt = false, callback) { + // let userInfos = uni.getStorageSync('userInfos'); + // console.log(userInfos); + // console.log(userInfos.username) + // let userName = userInfos.username; + let httpData = { + version: version, + // userName: userName + }; + // console.log(userName) + if (platform == "android") { + httpData.type = 1101; + } else { + httpData.type = 1102; + } + console.log("》》》》", 222222); + /* 接口入参说明 + * version: 应用当前版本号(已自动获取) + * type:平台(1101是安卓,1102是IOS) + */ + $http.get("/portal/v1/app/appVersion/versioninfo", httpData, { + isPrompt: isPrompt + }).then(res => { + /* res的数据说明 + * | 参数名称 | 一定返回 | 类型 | 描述 + * | -------------|--------- | --------- | ------------- | + * | versionCode | y | int | 版本号 | + * | versionName | y | String | 版本名称 | + * | versionInfo | y | String | 版本信息 | + * | forceUpdate | y | boolean | 是否强制更新 | + * | downloadUrl | y | String | 版本下载链接(IOS安装包更新请放跳转store应用商店链接,安卓apk和wgt文件放文件下载链接) | + */ + console.log("》》》》", 333333333); + console.log(res) + console.log(JSON.parse(res)); + console.log(JSON.stringify(JSON.parse(res))) + console.log(JSON.parse(res).downloadUrl) + if (res && JSON.parse(res).downloadUrl && version < JSON.parse(res).versionCode) { + callback && callback(res); + } else if (isPrompt) { + uni.showToast({ + title: "暂无新版本", + icon: "none" + }); + } + }); +} +// 从服务器下载应用资源包 +export const getDownload = function(res) { + console.log("getDownload》》》》", res); + //let data = JSON.parse(res); + let data = res; + let popupData = { + progress: true, + buttonNum: 2 + }; + if (data.forceUpdate) { + popupData.buttonNum = 0; + } + let file = data.fileName + let dtask; + let lastProgressValue = 0; + console.log("》》》》", 44444444); + console.log("downloadUrl》》》》", data.downloadUrl); + downloadPopup(popupData, function(res) { + dtask = plus.downloader.createDownload(data.downloadUrl, { + // filename: '_doc/update/' + file + '/' + new Date().getTime() + '/' + filename: '_doc/update/' + new Date().getTime() + '/' + file + }, function(download, status) { + console.log("download=====:" + JSON.stringify(download)); + console.log("status=====:" + status); + if (status == 200) { + res.change({ + progressValue: 100, + progressTip: "正在安装文件...", + progress: true, + buttonNum: 0 + }); + console.log(download.filename) + plus.runtime.install(download.filename, { + force: false + }, + function() { + // plus.runtime.restart();//下载后重启app + res.change({ + contentText: "应用资源更新完成!", + buttonNum: 1, + progress: false + }); + }, + function(e) { + res.cancel(); + plus.nativeUI.alert("安装文件失败[" + e.code + "]:" + e.message); + }); + } else { + res.change({ + contentText: "文件下载失败...", + buttonNum: 1, + progress: false + }); + } + }); + dtask.start(); + dtask.addEventListener("statechanged", function(task, status) { + switch (task.state) { + case 1: // 开始 + res.change({ + progressValue: 0, + progressTip: "准备下载...", + progress: true + }); + break; + case 2: // 已连接到服务器 + res.change({ + progressValue: 0, + progressTip: "开始下载...", + progress: true + }); + break; + case 3: + const progress = parseInt(task.downloadedSize / task.totalSize * 100); + if (progress - lastProgressValue >= 2) { + lastProgressValue = progress; + res.change({ + progressValue: progress, + progressTip: "已下载" + progress + "%", + progress: true + }); + } + + break; + } + }); + }, function() { + // 取消下载 + dtask && dtask.abort(); + uni.showToast({ + title: "已取消下载", + icon: "none" + }); + }, + function() { + // 重启APP + plus.runtime.restart(); + }); +} +// 文字换行 +function drawtext(text, maxWidth) { + debugger + let textArr = text.split(" "); + let len = textArr.length; + // 上个节点 + let previousNode = 0; + // 记录节点宽度 + let nodeWidth = 0; + // 文本换行数组 + let rowText = []; + // 如果是字母,侧保存长度 + let letterWidth = 0; + // 汉字宽度 + let chineseWidth = 14; + // otherFont宽度 + let otherWidth = 7; + for (let i = 0; i < len; i++) { + if (/[\u4e00-\u9fa5]|[\uFE30-\uFFA0]/g.test(textArr[i])) { + if (letterWidth > 0) { + if (nodeWidth + chineseWidth + letterWidth * otherWidth > maxWidth) { + rowText.push({ + type: "text", + content: text.substring(previousNode, i) + }); + previousNode = i; + nodeWidth = chineseWidth; + letterWidth = 0; + } else { + nodeWidth += chineseWidth + letterWidth * otherWidth; + letterWidth = 0; + } + } else { + if (nodeWidth + chineseWidth > maxWidth) { + rowText.push({ + type: "text", + content: text.substring(previousNode, i) + }); + previousNode = i; + nodeWidth = chineseWidth; + } else { + nodeWidth += chineseWidth; + } + } + } else { + if (/\n/g.test(textArr[i])) { + rowText.push({ + type: "break", + content: text.substring(previousNode, i) + }); + previousNode = i + 1; + nodeWidth = 0; + letterWidth = 0; + } else if (textArr[i] == "\\" && textArr[i + 1] == "n") { + rowText.push({ + type: "break", + content: text.substring(previousNode, i) + }); + previousNode = i + 2; + nodeWidth = 0; + letterWidth = 0; + } else if (/[a-zA-Z0-9]/g.test(textArr[i])) { + letterWidth += 1; + if (nodeWidth + letterWidth * otherWidth > maxWidth) { + rowText.push({ + type: "text", + content: text.substring(previousNode, i + 1 - letterWidth) + }); + previousNode = i + 1 - letterWidth; + nodeWidth = letterWidth * otherWidth; + letterWidth = 0; + } + } else { + if (nodeWidth + otherWidth > maxWidth) { + rowText.push({ + type: "text", + content: text.substring(previousNode, i) + }); + previousNode = i; + nodeWidth = otherWidth; + } else { + nodeWidth += otherWidth; + } + } + } + } + if (previousNode < len) { + rowText.push({ + type: "text", + // content: text.substring(previousNode, len) + content: text + }); + } + return rowText; +} +// 是否更新弹窗 +function updatePopup(res, callback) { + console.log(res); + //let data = JSON.parse(res); + let data = res; + console.log(data.versionInfo) + // 弹窗遮罩层 + let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层 + top: '0px', + left: '0px', + height: '100%', + width: '100%', + backgroundColor: 'rgba(0,0,0,0.5)' + }); + + // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心 + const screenWidth = plus.screen.resolutionWidth; + const screenHeight = plus.screen.resolutionHeight; + //弹窗容器宽度 + const popupViewWidth = screenWidth * 0.7; + // 弹窗容器的Padding + const viewContentPadding = 20; + // 弹窗容器的宽度 + const viewContentWidth = parseInt(popupViewWidth - (viewContentPadding * 2)); + // 描述的列表 + const descriptionList = drawtext(data.versionInfo, viewContentWidth); + // 弹窗容器高度 + let popupViewHeight = 80 + 20 + 20 + 90 + 10; + let popupViewContentList = [{ + src: $iconUrl, + id: "logo", + tag: "img", + position: { + top: "0px", + left: (popupViewWidth - 124) / 2 + "px", + width: "124px", + height: "80px", + } + }, + { + tag: 'font', + id: 'title', + text: "发现新版本" + data.versionName, + textStyles: { + size: '18px', + color: "#333", + weight: "bold", + whiteSpace: "normal" + }, + position: { + top: '90px', + left: viewContentPadding + "px", + width: viewContentWidth + "px", + height: "30px", + } + } + ]; + const textHeight = 18; + let contentTop = 130; + descriptionList.forEach((item, index) => { + if (index > 0) { + popupViewHeight += textHeight; + contentTop += textHeight; + } + popupViewContentList.push({ + tag: 'font', + id: 'content' + index + 1, + text: item.content, + textStyles: { + size: '14px', + color: "#666", + lineSpacing: "50%", + align: "left" + }, + position: { + top: contentTop + "px", + left: viewContentPadding + "px", + width: viewContentWidth + "px", + height: textHeight + "px", + } + }); + if (item.type == "break") { + contentTop += 10; + popupViewHeight += 10; + } + }); + // 弹窗内容 + let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单 + tag: "rect", + top: (screenHeight - popupViewHeight) / 2 + "px", + left: '15%', + height: popupViewHeight + "px", + width: "70%" + }); + // 绘制白色背景 + popupView.drawRect({ + color: "#FFFFFF", + radius: "8px" + }, { + top: "40px", + height: popupViewHeight - 40 + "px", + }); + // 绘制底边按钮 + popupView.drawRect({ + radius: "3px", + borderColor: "#f1f1f1", + borderWidth: "1px", + }, { + bottom: viewContentPadding + 'px', + left: viewContentPadding + "px", + width: (viewContentWidth - viewContentPadding) / 2 + "px", + height: "30px", + }); + // 绘制底边按钮 + popupView.drawRect({ + radius: "3px", + color: $mainColor, + }, { + bottom: viewContentPadding + 'px', + left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", + width: (viewContentWidth - viewContentPadding) / 2 + "px", + height: "30px", + }); + popupViewContentList.push({ + tag: 'font', + id: 'cancelText', + text: "暂不升级", + textStyles: { + size: '14px', + color: "#666", + lineSpacing: "0%", + whiteSpace: "normal" + }, + position: { + bottom: viewContentPadding + 'px', + left: viewContentPadding + "px", + width: (viewContentWidth - viewContentPadding) / 2 + "px", + height: "30px", + } + }); + popupViewContentList.push({ + tag: 'font', + id: 'confirmText', + text: "立即升级", + textStyles: { + size: '14px', + color: "#FFF", + lineSpacing: "0%", + whiteSpace: "normal" + }, + position: { + bottom: viewContentPadding + 'px', + left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", + width: (viewContentWidth - viewContentPadding) / 2 + "px", + height: "30px", + } + }); + popupView.draw(popupViewContentList); + popupView.addEventListener("click", function(e) { + let maxTop = popupViewHeight - viewContentPadding; + let maxLeft = popupViewWidth - viewContentPadding; + let buttonWidth = (viewContentWidth - viewContentPadding) / 2; + if (e.clientY > maxTop - 30 && e.clientY < maxTop) { + // 暂不升级 + if (e.clientX > viewContentPadding && e.clientX < maxLeft - buttonWidth - viewContentPadding) { + maskLayer.hide(); + popupView.hide(); + } else if (e.clientX > maxLeft - buttonWidth && e.clientX < maxLeft) { + // 立即升级 + maskLayer.hide(); + popupView.hide(); + callback && callback(); + } + } + }); + // 点击遮罩层 + maskLayer.addEventListener("click", function() { //处理遮罩层点击 + maskLayer.hide(); + popupView.hide(); + }); + // 显示弹窗 + maskLayer.show(); + popupView.show(); +} +// 文件下载的弹窗绘图 +function downloadPopupDrawing(data) { + // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心 + const screenWidth = plus.screen.resolutionWidth; + const screenHeight = plus.screen.resolutionHeight; + //弹窗容器宽度 + const popupViewWidth = screenWidth * 0.7; + // 弹窗容器的Padding + const viewContentPadding = 20; + // 弹窗容器的宽度 + const viewContentWidth = popupViewWidth - (viewContentPadding * 2); + // 弹窗容器高度 + let popupViewHeight = viewContentPadding * 3 + 60; + let progressTip = data.progressTip || "准备下载..."; + let contentText = data.contentText || "正在为您更新,请耐心等待"; + let elementList = [{ + tag: 'rect', //背景色 + color: '#FFFFFF', + rectStyles: { + radius: "8px" + } + }, + { + tag: 'font', + id: 'title', + text: "升级APP", + textStyles: { + size: '16px', + color: "#333", + weight: "bold", + verticalAlign: "middle", + whiteSpace: "normal" + }, + position: { + top: viewContentPadding + 'px', + height: "30px", + } + }, + { + tag: 'font', + id: 'content', + text: contentText, + textStyles: { + size: '14px', + color: "#333", + verticalAlign: "middle", + whiteSpace: "normal" + }, + position: { + top: viewContentPadding * 2 + 30 + 'px', + height: "20px", + } + } + ]; + // 是否有进度条 + if (data.progress) { + popupViewHeight += viewContentPadding + 40; + elementList = elementList.concat([{ + tag: 'font', + id: 'progressValue', + text: progressTip, + textStyles: { + size: '14px', + color: $mainColor, + whiteSpace: "normal" + }, + position: { + top: viewContentPadding * 4 + 20 + 'px', + height: "30px" + } + }, + { + tag: 'rect', //绘制进度条背景 + id: 'progressBg', + rectStyles: { + radius: "4px", + borderColor: "#f1f1f1", + borderWidth: "1px", + }, + position: { + top: viewContentPadding * 4 + 60 + 'px', + left: viewContentPadding + "px", + width: viewContentWidth + "px", + height: "8px" + } + }, + ]); + } + if (data.buttonNum == 2) { + popupViewHeight += viewContentPadding + 30; + elementList = elementList.concat([{ + tag: 'rect', //绘制底边按钮 + rectStyles: { + radius: "3px", + borderColor: "#f1f1f1", + borderWidth: "1px", + }, + position: { + bottom: viewContentPadding + 'px', + left: viewContentPadding + "px", + width: (viewContentWidth - viewContentPadding) / 2 + "px", + height: "30px" + } + }, + { + tag: 'rect', //绘制底边按钮 + rectStyles: { + radius: "3px", + color: $mainColor + }, + position: { + bottom: viewContentPadding + 'px', + left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", + width: (viewContentWidth - viewContentPadding) / 2 + "px", + height: "30px" + } + }, + { + tag: 'font', + id: 'cancelText', + text: "取消下载", + textStyles: { + size: '14px', + color: "#666", + lineSpacing: "0%", + whiteSpace: "normal" + }, + position: { + bottom: viewContentPadding + 'px', + left: viewContentPadding + "px", + width: (viewContentWidth - viewContentPadding) / 2 + "px", + height: "30px", + } + }, + { + tag: 'font', + id: 'confirmText', + text: "后台下载", + textStyles: { + size: '14px', + color: "#FFF", + lineSpacing: "0%", + whiteSpace: "normal" + }, + position: { + bottom: viewContentPadding + 'px', + left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", + width: (viewContentWidth - viewContentPadding) / 2 + "px", + height: "30px", + } + } + ]); + } + if (data.buttonNum == 1) { + popupViewHeight += viewContentPadding + 40; + elementList = elementList.concat([{ + tag: 'rect', //绘制底边按钮 + rectStyles: { + radius: "6px", + color: $mainColor + }, + position: { + bottom: viewContentPadding + 'px', + left: viewContentPadding + "px", + width: viewContentWidth + "px", + height: "40px" + } + }, + { + tag: 'font', + id: 'confirmText', + text: "关闭", + textStyles: { + size: '14px', + color: "#FFF", + lineSpacing: "0%", + }, + position: { + bottom: viewContentPadding + 'px', + left: viewContentPadding + "px", + width: viewContentWidth + "px", + height: "40px" + } + } + ]); + } + return { + popupViewHeight: popupViewHeight, + popupViewWidth: popupViewWidth, + screenHeight: screenHeight, + viewContentWidth: viewContentWidth, + viewContentPadding: viewContentPadding, + elementList: elementList + }; +} +// 文件下载的弹窗 +function downloadPopup(data, callback, cancelCallback, rebootCallback) { + // 弹窗遮罩层 + let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层 + top: '0px', + left: '0px', + height: '100%', + width: '100%', + backgroundColor: 'rgba(0,0,0,0.5)' + }); + let popupViewData = downloadPopupDrawing(data); + // 弹窗内容 + let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单 + tag: "rect", + top: (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px", + left: '15%', + height: popupViewData.popupViewHeight + "px", + width: "70%", + }); + let progressValue = 0; + let progressTip = 0; + let contentText = 0; + let buttonNum = 2; + if (data.buttonNum >= 0) { + buttonNum = data.buttonNum; + } + popupView.draw(popupViewData.elementList); + popupView.addEventListener("click", function(e) { + let maxTop = popupViewData.popupViewHeight - popupViewData.viewContentPadding; + let maxLeft = popupViewData.popupViewWidth - popupViewData.viewContentPadding; + if (e.clientY > maxTop - 40 && e.clientY < maxTop) { + if (buttonNum == 1) { + // 单按钮 + if (e.clientX > popupViewData.viewContentPadding && e.clientX < maxLeft) { + maskLayer.hide(); + popupView.hide(); + rebootCallback && rebootCallback(); + } + } else if (buttonNum == 2) { + // 双按钮 + let buttonWidth = (popupViewData.viewContentWidth - popupViewData.viewContentPadding) / 2; + if (e.clientX > popupViewData.viewContentPadding && e.clientX < maxLeft - buttonWidth - + popupViewData.viewContentPadding) { + maskLayer.hide(); + popupView.hide(); + cancelCallback && cancelCallback(); + } else if (e.clientX > maxLeft - buttonWidth && e.clientX < maxLeft) { + maskLayer.hide(); + popupView.hide(); + } + } + } + }); + // 显示弹窗 + maskLayer.show(); + popupView.show(); + // 改变进度条 + callback({ + change: function(res) { + let progressElement = []; + if (res.progressValue) { + progressValue = res.progressValue; + // 绘制进度条 + progressElement.push({ + tag: 'rect', //绘制进度条背景 + id: 'progressValueBg', + rectStyles: { + radius: "4px", + color: $mainColor + }, + position: { + top: popupViewData.viewContentPadding * 4 + 60 + 'px', + left: popupViewData.viewContentPadding + "px", + width: popupViewData.viewContentWidth * (res.progressValue / 100) + "px", + height: "8px" + } + }); + } + if (res.progressTip) { + progressTip = res.progressTip; + progressElement.push({ + tag: 'font', + id: 'progressValue', + text: res.progressTip, + textStyles: { + size: '14px', + color: $mainColor, + whiteSpace: "normal" + }, + position: { + top: popupViewData.viewContentPadding * 4 + 20 + 'px', + height: "30px" + } + }); + } + if (res.contentText) { + contentText = res.contentText; + progressElement.push({ + tag: 'font', + id: 'content', + text: res.contentText, + textStyles: { + size: '16px', + color: "#333", + whiteSpace: "normal" + }, + position: { + top: popupViewData.viewContentPadding * 2 + 30 + 'px', + height: "30px", + } + }); + } + if (res.buttonNum >= 0 && buttonNum != res.buttonNum) { + buttonNum = res.buttonNum; + popupView.reset(); + popupViewData = downloadPopupDrawing(Object.assign({ + progressValue: progressValue, + progressTip: progressTip, + contentText: contentText, + }, res)); + let newElement = []; + popupViewData.elementList.map((item, index) => { + let have = false; + progressElement.forEach((childItem, childIndex) => { + if (item.id == childItem.id) { + have = true; + } + }); + if (!have) { + newElement.push(item); + } + }); + progressElement = newElement.concat(progressElement); + popupView.setStyle({ + tag: "rect", + top: (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px", + left: '15%', + height: popupViewData.popupViewHeight + "px", + width: "70%", + }); + popupView.draw(progressElement); + } else { + popupView.draw(progressElement); + } + }, + cancel: function() { + maskLayer.hide(); + popupView.hide(); + } + }); +} +export default function(isPrompt = false) { + getCurrentNo(version => { + console.log("》》》》", version); + getServerNo(version.versionCode, isPrompt, data => { + let res = JSON.parse(data); + console.log("》》》》", 6666666); + console.log("》》》》", res.downloadUrl); + if (res.forceUpdate) { + if (/\.wgt$/i.test(res.downloadUrl)) { + getDownload(res); + } else if (/\.apk$/i.test(res.downloadUrl)) { + plus.runtime.openURL(res.downloadUrl); + } else { + if (platform == "android") { + getDownload(res); + } else { + plus.runtime.openURL(res.downloadUrl); + } + } + } else { + updatePopup(res, function() { + if (/\.wgt$/i.test(res.downloadUrl)) { + getDownload(res); + } else if (/\.html$/i.test(res.downloadUrl)) { + plus.runtime.openURL(res.downloadUrl); + } else { + if (platform == "android") { + getDownload(res); + } else { + plus.runtime.openURL(res.downloadUrl); + } + } + }); + } + }); + }); +} +// #endif \ No newline at end of file diff --git a/supervise-uniapp/plugins/request/fileUpload.js b/supervise-uniapp/plugins/request/fileUpload.js new file mode 100644 index 00000000..e1fc1c1a --- /dev/null +++ b/supervise-uniapp/plugins/request/fileUpload.js @@ -0,0 +1,390 @@ +import request from "./request.js"; +const qiniuUploader = require("./qiniuUploader"); +export default class fileUpload extends request { + constructor(props) { + // 调用实现父类的构造函数 + super(props); + } + //七牛云上传图片 + qnImgUpload(data = {}, options = {}) { + const _this = this; + return new Promise((resolve, reject) => { + uni.chooseImage({ + count: data.count || 9, //默认9 + sizeType: data.sizeType || ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 + sourceType: data.sourceType || ['album', 'camera'], //从相册选择 + success: function(res) { + _this.qnFileUpload({ + files: res.tempFiles, + ...data + }, options).then(resolve, reject); + } + }); + }); + } + //七牛云上传文件命名 + randomChar(l, url = "") { + const x = "0123456789qwertyuioplkjhgfdsazxcvbnm"; + let tmp = ""; + let time = new Date(); + for (let i = 0; i < l; i++) { + tmp += x.charAt(Math.ceil(Math.random() * 100000000) % x.length); + } + return ( + "file/" + + url + + time.getTime() + + tmp + ); + } + //七牛云文件上传(支持多张上传) + qnFileUpload(data = {}, options = {}) { + const _this = this; + let requestInfo = { + ...data, + ...this.config, + ...options, + header: {}, + method: "FILE" + }; + return new Promise((resolve, reject) => { + //请求前回调 + if (_this.requestStart) { + let requestStart = _this.requestStart(requestInfo); + if (typeof requestStart == "object") { + requestInfo.load = requestStart.load; + requestInfo.files = requestStart.files; + } else { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "请求开始拦截器未通过", + statusCode: 0 + }); + reject({ + errMsg: "请求开始拦截器未通过", + statusCode: 0 + }); + return; + } + } + if (Array.isArray(requestInfo.files)) { + let len = requestInfo.files.length; + let imageList = new Array; + if(_this.getQnToken){ + _this.getQnToken(qnRes => { + /* + *接口返回参数: + *visitPrefix:访问文件的域名 + *token:七牛云上传token + *folderPath:上传的文件夹 + *region: 地区 默认为:SCN + */ + uploadFile(0); + function uploadFile(i) { + let fileData = { + fileIndex: i, + files: requestInfo.files, + size: requestInfo.files[i].size + }; + // #ifdef H5 + fileData.name = requestInfo.files[i].name; + fileData.type = requestInfo.files[i].type; + // #endif + // 交给七牛上传 + qiniuUploader.upload(requestInfo.files[i].path, (res) => { + fileData.url = res.imageURL; + requestInfo.onEachUpdate && requestInfo.onEachUpdate({ + url: res.imageURL, + ...fileData + }); + imageList.push(res.imageURL); + if (len - 1 > i) { + uploadFile(i + 1); + } else { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "request:ok", + statusCode: 200, + data: imageList + }); + resolve(imageList); + } + }, (error) => { + console.log('error: ' + error); + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, error); + reject(error) + }, { + region: qnRes.region || 'SCN', //地区 + domain: qnRes.visitPrefix, // bucket 域名,下载资源时用到。 + key: _this.randomChar(8, qnRes.folderPath), + uptoken: qnRes.token, // 由其他程序生成七牛 uptoken + uptokenURL: 'UpTokenURL.com/uptoken' // 上传地址 + }, (res) => { + console.log(requestInfo); + requestInfo.onProgressUpdate && requestInfo.onProgressUpdate(Object.assign({}, fileData, res)); + // console.log('上传进度', res.progress) + // console.log('已经上传的数据长度', res.totalBytesSent) + // console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend) + }); + } + }); + } else { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "请添加七牛云回调方法:getQnToken", + statusCode: 0 + }); + reject({ + errMsg: "请添加七牛云回调方法:getQnToken", + statusCode: 0 + }); + return; + } + } else { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "files 必须是数组类型", + statusCode: 0 + }); + reject({ + errMsg: "files 必须是数组类型", + statusCode: 0 + }); + }; + }); + + } + //本地服务器图片上传 + urlImgUpload(url = '', data = {}, options = {}) { + const _this = this; + return new Promise((resolve, reject) => { + uni.chooseImage({ + count: data.count || 9, //默认9 + sizeType: data.sizeType || ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 + sourceType: data.sourceType || ['album', 'camera'], //从相册选择 + success: function(res) { + _this.urlFileUpload(url, { + ...data, + files: res.tempFiles + }, options).then(resolve, reject); + } + }); + }); + } + //本地服务器文件上传方法 + urlFileUpload(url = '', data = {}, options = {}) { + let requestInfo = this.getDefault({ + ...data, + url: url, + method: "FILE" + }, options); + const _this = this; + return new Promise((resolve, reject) => { + //请求前回调 + if (_this.requestStart) { + let requestStart = _this.requestStart(requestInfo); + if (typeof requestStart == "object") { + requestInfo.data = requestStart.data; + requestInfo.header = requestStart.header; + requestInfo.isPrompt = requestStart.isPrompt; + requestInfo.load = requestStart.load; + requestInfo.isFactory = requestStart.isFactory; + requestInfo.files = requestStart.files; + } else { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "请求开始拦截器未通过", + statusCode: 0 + }); + reject({ + errMsg: "请求开始拦截器未通过", + statusCode: 0 + }); + return; + } + } + // 本地文件上传去掉默认Content-Type + if(requestInfo.header['Content-Type']){ + delete requestInfo.header['Content-Type']; + } + if (Array.isArray(requestInfo.files)) { + // #ifdef APP-PLUS || H5 + let files = []; + let fileData = { + files: requestInfo.files, + name: requestInfo.name || "file" + }; + requestInfo.files.forEach(item => { + files.push({ + uri: item.path, + name: requestInfo.name || "file" + }); + }); + let config = { + url: requestInfo.url, + files: files, + header: requestInfo.header, //加入请求头 + success: (response) => { + if (typeof(response.data) == "string") { + response.data = JSON.parse(response.data); + } + //是否用外部的数据处理方法 + if (requestInfo.isFactory && _this.dataFactory) { + //数据处理 + _this.dataFactory({ + ...requestInfo, + response: response, + resolve: function(data) { + requestInfo.onEachUpdate && requestInfo.onEachUpdate({ + data: data, + ...fileData + }); + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "request:ok", + statusCode: 200, + data: data + }); + resolve(data); + }, + reject: function(err) { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "数据工厂返回错误", + statusCode: 0, + data: err + }); + reject(err); + } + }); + } else { + requestInfo.onEachUpdate && requestInfo.onEachUpdate({ + data: response, + ...fileData + }); + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, response); + resolve(response); + } + }, + fail: (err) => { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, err); + reject(err); + } + }; + if (requestInfo.data) { + config.formData = requestInfo.data; + } + const uploadTask = uni.uploadFile(config); + uploadTask.onProgressUpdate(res => { + requestInfo.onProgressUpdate && requestInfo.onProgressUpdate(Object.assign({}, fileData, res)); + }); + // #endif + // #ifdef MP + const len = requestInfo.files.length - 1; + let fileList = new Array; + fileUpload(0); + + function fileUpload(i) { + let fileData = { + fileIndex: i, + files: requestInfo.files, + size: requestInfo.files[i].size + }; + // #ifdef H5 + fileData.name = requestInfo.files[i].name; + fileData.type = requestInfo.files[i].type; + // #endif + let config = { + url: requestInfo.url, + filePath: requestInfo.files[i].path, + header: requestInfo.header, //加入请求头 + name: requestInfo.name || "file", + success: (response) => { + if (typeof(response.data) == "string") { + response.data = JSON.parse(response.data); + } + //是否用外部的数据处理方法 + if (requestInfo.isFactory && _this.dataFactory) { + //数据处理 + _this.dataFactory({ + ...requestInfo, + response: response, + resolve: function(data) { + requestInfo.onEachUpdate && requestInfo.onEachUpdate({ + data: data, + ...fileData + }); + fileList.push(data); + if (len <= i) { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "request:ok", + statusCode: 200, + data: fileList + }); + resolve(fileList); + } else { + fileUpload(i + 1); + } + }, + reject: function(err) { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "数据工厂返回错误", + statusCode: 0, + data: err + }); + reject(err); + } + }); + } else { + requestInfo.onEachUpdate && requestInfo.onEachUpdate({ + data: response, + ...fileData + }); + fileList.push(response); + if (len <= i) { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "request:ok", + statusCode: 200, + data: fileList + }); + resolve(fileList); + } else { + fileUpload(i + 1); + } + } + }, + fail: (err) => { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, err); + reject(err); + } + }; + if (requestInfo.data) { + config.formData = requestInfo.data; + } + const uploadTask = uni.uploadFile(config); + uploadTask.onProgressUpdate(res => { + requestInfo.onProgressUpdate && requestInfo.onProgressUpdate(Object.assign({}, fileData, res)); + }); + } + // #endif + } else { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "files 必须是数组类型", + statusCode: 0 + }); + reject({ + errMsg: "files 必须是数组类型", + statusCode: 0 + }) + } + }); + } +} diff --git a/supervise-uniapp/plugins/request/index.js b/supervise-uniapp/plugins/request/index.js new file mode 100644 index 00000000..8884f51d --- /dev/null +++ b/supervise-uniapp/plugins/request/index.js @@ -0,0 +1,7 @@ +/***************纯粹的数据请求(如果使用这种可以删除掉fileUpload.js)******************/ +// import request from "./request.js"; +// export default request; + +/********数据请求同时继承了文件上传(包括七牛云上传)************/ +import fileUpload from "./fileUpload.js"; +export default fileUpload; \ No newline at end of file diff --git a/supervise-uniapp/plugins/request/qiniuUploader.js b/supervise-uniapp/plugins/request/qiniuUploader.js new file mode 100644 index 00000000..138c80e1 --- /dev/null +++ b/supervise-uniapp/plugins/request/qiniuUploader.js @@ -0,0 +1,169 @@ +// created by gpake +(function () { + + var config = { + qiniuRegion: '', + qiniuImageURLPrefix: '', + qiniuUploadToken: '', + qiniuUploadTokenURL: '', + qiniuUploadTokenFunction: null, + qiniuShouldUseQiniuFileName: false + } + + module.exports = { + init: init, + upload: upload, + } + + // 在整个程序生命周期中,只需要 init 一次即可 + // 如果需要变更参数,再调用 init 即可 + function init(options) { + config = { + qiniuRegion: '', + qiniuImageURLPrefix: '', + qiniuUploadToken: '', + qiniuUploadTokenURL: '', + qiniuUploadTokenFunction: null, + qiniuShouldUseQiniuFileName: false + }; + updateConfigWithOptions(options); + } + + function updateConfigWithOptions(options) { + if (options.region) { + config.qiniuRegion = options.region; + } else { + console.error('qiniu uploader need your bucket region'); + } + if (options.uptoken) { + config.qiniuUploadToken = options.uptoken; + } else if (options.uptokenURL) { + config.qiniuUploadTokenURL = options.uptokenURL; + } else if (options.uptokenFunc) { + config.qiniuUploadTokenFunction = options.uptokenFunc; + } + if (options.domain) { + config.qiniuImageURLPrefix = options.domain; + } + config.qiniuShouldUseQiniuFileName = options.shouldUseQiniuFileName + } + + function upload(filePath, success, fail, options, progress, cancelTask) { + if (null == filePath) { + console.error('qiniu uploader need filePath to upload'); + return; + } + if (options) { + updateConfigWithOptions(options); + } + if (config.qiniuUploadToken) { + doUpload(filePath, success, fail, options, progress, cancelTask); + } else if (config.qiniuUploadTokenURL) { + getQiniuToken(function () { + doUpload(filePath, success, fail, options, progress, cancelTask); + }); + } else if (config.qiniuUploadTokenFunction) { + config.qiniuUploadToken = config.qiniuUploadTokenFunction(); + if (null == config.qiniuUploadToken && config.qiniuUploadToken.length > 0) { + console.error('qiniu UploadTokenFunction result is null, please check the return value'); + return + } + doUpload(filePath, success, fail, options, progress, cancelTask); + } else { + console.error('qiniu uploader need one of [uptoken, uptokenURL, uptokenFunc]'); + return; + } + } + + function doUpload(filePath, success, fail, options, progress, cancelTask) { + if (null == config.qiniuUploadToken && config.qiniuUploadToken.length > 0) { + console.error('qiniu UploadToken is null, please check the init config or networking'); + return + } + var url = uploadURLFromRegionCode(config.qiniuRegion); + var fileName = filePath.split('//')[1]; + if (options && options.key) { + fileName = options.key; + } + var formData = { + 'token': config.qiniuUploadToken + }; + if (!config.qiniuShouldUseQiniuFileName) { + formData['key'] = fileName + } + var uploadTask = wx.uploadFile({ + url: url, + filePath: filePath, + name: 'file', + formData: formData, + success: function (res) { + var dataString = res.data + if (res.data.hasOwnProperty('type') && res.data.type === 'Buffer') { + dataString = String.fromCharCode.apply(null, res.data.data) + } + try { + var dataObject = JSON.parse(dataString); + //do something + var imageUrl = config.qiniuImageURLPrefix + '/' + dataObject.key; + dataObject.imageURL = imageUrl; + if (success) { + success(dataObject); + } + } catch (e) { + console.log('parse JSON failed, origin String is: ' + dataString) + if (fail) { + fail(e); + } + } + }, + fail: function (error) { + console.error(error); + if (fail) { + fail(error); + } + } + }) + + uploadTask.onProgressUpdate((res) => { + progress && progress(res) + }) + + cancelTask && cancelTask(() => { + uploadTask.abort() + }) + } + + function getQiniuToken(callback) { + wx.request({ + url: config.qiniuUploadTokenURL, + success: function (res) { + var token = res.data.uptoken; + if (token && token.length > 0) { + config.qiniuUploadToken = token; + if (callback) { + callback(); + } + } else { + console.error('qiniuUploader cannot get your token, please check the uptokenURL or server') + } + }, + fail: function (error) { + console.error('qiniu UploadToken is null, please check the init config or networking: ' + error); + } + }) + } + + function uploadURLFromRegionCode(code) { + var uploadURL = null; + switch (code) { + case 'ECN': uploadURL = 'https://up.qbox.me'; break; + case 'NCN': uploadURL = 'https://up-z1.qbox.me'; break; + case 'SCN': uploadURL = 'https://up-z2.qbox.me'; break; + case 'NA': uploadURL = 'https://up-na0.qbox.me'; break; + case 'ASG': uploadURL = 'https://up-as0.qbox.me'; break; + default: console.error('please make the region is with one of [ECN, SCN, NCN, NA, ASG]'); + } + return uploadURL; + } + +})(); \ No newline at end of file diff --git a/supervise-uniapp/plugins/request/request.js b/supervise-uniapp/plugins/request/request.js new file mode 100644 index 00000000..2eb27d15 --- /dev/null +++ b/supervise-uniapp/plugins/request/request.js @@ -0,0 +1,230 @@ +export default class request { + constructor(options) { + //请求公共地址 + this.baseUrl = options.baseUrl || ""; + //公共文件上传请求地址 + this.fileUrl = options.fileUrl || ""; + //默认请求头 + this.header = options.header || {}; + //默认配置 + this.config = { + isPrompt: options.isPrompt === false ? false : true, + load: options.load === false ? false : true, + isFactory: options.isFactory === false ? false : true, + loadMore: options.loadMore === false ? false : true + }; + } + + // 获取默认信息 + getDefault(data, options = {}) { + //判断url是不是链接 + let urlType = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~/])+$/.test( + data.url); + let config = Object.assign({}, this.config, options, data); + if (data.method == "FILE") { + config.url = urlType ? data.url : this.fileUrl + data.url; + } else { + config.url = urlType ? data.url : this.baseUrl + data.url; + } + //请求头 + if (options.header) { + config.header = Object.assign({}, this.header, options.header); + } else if (data.header) { + config.header = Object.assign({}, this.header, data.header); + } else { + config.header = this.header; + } + return config; + } + + //post请求 + post(url = '', data = {}, options = {}) { + return this.request({ + method: "POST", + data: data, + url: url, + ...options + }); + } + + //get请求 + get(url = '', data = {}, options = {}) { + return this.request({ + method: "GET", + data: data, + url: url, + ...options + }); + } + + //put请求 + put(url = '', data = {}, options = {}) { + return this.request({ + method: "PUT", + data: data, + url: url, + ...options + }); + } + + //delete请求 + delete(url = '', data = {}, options = {}) { + return this.request({ + method: "DELETE", + data: data, + url: url, + ...options + }); + } + + //接口请求方法 + request(data) { + return new Promise((resolve, reject) => { + if (!data.url) { + console.log("request缺失数据url"); + reject({ + errMsg: "缺失数据url", + statusCode: 0 + }); + return; + } + let requestInfo = this.getDefault(data); + + //请求前回调 + if (this.requestStart) { + let requestStart = this.requestStart(requestInfo); + if (typeof requestStart == "object") { + requestInfo.data = requestStart.data; + requestInfo.header = requestStart.header; + requestInfo.isPrompt = requestStart.isPrompt; + requestInfo.load = requestStart.load; + requestInfo.isFactory = requestStart.isFactory; + } else { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "请求开始拦截器未通过", + statusCode: 0 + }); + reject({ + errMsg: "请求开始拦截器未通过", + statusCode: 0 + }); + return; + } + } + console.log("url: requestInfo.url》》》》", requestInfo.url) + console.log("url: requestInfo.header》》》》", requestInfo.header) + let requestData = { + url: requestInfo.url, + header: requestInfo.header, //加入请求头 + + success: (res) => { + //请求完成回调 + this.requestEnd && this.requestEnd(requestInfo, res); + //是否用外部的数据处理方法 + if (requestInfo.isFactory && this.dataFactory) { + //数据处理 + this.dataFactory({ + ...requestInfo, + response: res, + resolve: resolve, + reject: reject + }); + } else { + resolve(res); + } + }, + fail: (err) => { + console.log("err"); + //请求完成回调 + this.requestEnd && this.requestEnd(requestInfo, err); + reject(err); + } + }; + //请求类型 + if (requestInfo.method) { + requestData.method = requestInfo.method; + } + if (requestInfo.data) { + requestData.data = requestInfo.data; + } + // #ifdef MP-WEIXIN || MP-ALIPAY + if (requestInfo.timeout) { + requestData.timeout = requestInfo.timeout; + } + // #endif + if (requestInfo.dataType) { + requestData.dataType = requestInfo.dataType; + } + // #ifndef APP-PLUS || MP-ALIPAY + if (requestInfo.responseType) { + requestData.responseType = requestInfo.responseType; + } + // #endif + // #ifdef H5 + if (requestInfo.withCredentials) { + requestData.withCredentials = requestInfo.withCredentials; + } + // #endif + uni.request(requestData); + }); + } + //jsonp请求(只限于H5使用) + jsonp(url = '', data = {}, options = {}) { + let requestInfo = this.getDefault({ + method: "JSONP", + data: data, + url: url, + }, options); + let dataStr = ''; + Object.keys(data).forEach(key => { + dataStr += key + '=' + data[key] + '&'; + }); + //匹配最后一个&并去除 + if (dataStr !== '') { + dataStr = dataStr.substr(0, dataStr.lastIndexOf('&')); + } + requestInfo.url = requestInfo.url + '?' + dataStr; + const _this = this; + return new Promise((resolve, reject) => { + let callbackName = "callback" + Math.ceil(Math.random() * 1000000); + if (_this.requestStart) { + requestInfo.data = data; + let requestStart = _this.requestStart(requestInfo); + if (typeof requestStart == "object") { + requestInfo.data = requestStart.data; + requestInfo.header = requestStart.header; + requestInfo.isPrompt = requestStart.isPrompt; + requestInfo.load = requestStart.load; + requestInfo.isFactory = requestStart.isFactory; + } else { + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "请求开始拦截器未通过", + statusCode: 0 + }); + reject({ + errMsg: "请求开始拦截器未通过", + statusCode: 0 + }); + return; + } + } + // #ifdef H5 + window[callbackName] = function(data) { + resolve(data); + } + let script = document.createElement("script"); + script.src = requestInfo.url + "&callback=" + callbackName; + document.head.appendChild(script); + // 及时删除,防止加载过多的JS + document.head.removeChild(script); + // #endif + //请求完成回调 + _this.requestEnd && _this.requestEnd(requestInfo, { + errMsg: "request:ok", + statusCode: 200 + }); + }); + } +} diff --git a/supervise-uniapp/plugins/request/request.md b/supervise-uniapp/plugins/request/request.md new file mode 100644 index 00000000..2d59e5bb --- /dev/null +++ b/supervise-uniapp/plugins/request/request.md @@ -0,0 +1,229 @@ +# request请求、配置简单、批量上传图片、超强适应性(很方便的支持多域名请求) +1. 配置简单、源码清晰注释多、适用于一项目多域名请求、第三方请求、七牛云图片上传、本地服务器图片上传等等 +2. 支持请求`get`、`post`、`put`、`delete` +3. 自动显示请求加载动画(可单个接口关闭) +4. 全局`api`数据处理函数,只回调请求正确的数据(可单个接口关闭) +5. 未登录或登录失效自动拦截并调用登录方法(可单个接口关闭) +6. 全局自动提示接口抛出的错误信息(可单个接口关闭) +7. 支持 Promise +8. 支持拦截器 +9. 支持七牛云文件(图片)批量上传 +10. 支持本地服务器文件(图片)批量上传 +11. 支持上传文件拦截过滤 +12. 支持上传文件进度监听 +13. 支持上传文件单张成功回调 + +### QQ交流群(学习干货多多) 607391225 +![QQ交流群](http://qn.kemean.cn//upload/202004/14/15868301778472k7oubi6.png) + +### 常见问题 +1.接口请求成功了,没有返回数据或者数据是走的catch回调 + +答:`requestConfig.js` 请求配置文件里面,有一个`$http.dataFactory`方法,里面写的只是参考示例,`此方法需要开发者根据各自的接口返回类型修改` + +2.官方的方法有数据,本插件方法请求报错跨域问题 + +答:`requestConfig.js` 请求配置文件里面,`header`请求头设置的`content-type`请求类型需求和后台保持一致 + +3.登录后用户`token`怎么设置? + +答:`requestConfig.js` 请求配置文件里面,`$http.requestStart`请求开始拦截器里面设置 + +4.怎么判断上传的文件(图片)太大?怎么过滤掉太大的文件(图片)? + +答:`requestConfig.js` 请求配置文件里面,`$http.requestStart`请求开始拦截器里面设置 + +### 本次更新注意事项 +1. 所有的headers都改成了header(和官方统一) +2. 七牛云的获取token等信息提取到了`requestConfig.js`文件,参考如下 + +``` +// 添加获取七牛云token的方法 +$http.getQnToken = function(callback){ + //该地址需要开发者自行配置(每个后台的接口风格都不一样) + $http.get("api/kemean/aid/qn_upload").then(data => { + /* + *接口返回参数: + *visitPrefix:访问文件的域名 + *token:七牛云上传token + *folderPath:上传的文件夹 + */ + callback({ + visitPrefix: data.visitPrefix, + token: data.token, + folderPath: data.folderPath + }); + }); +} +``` + +### 文件说明 +1. `request => request.js` 请求方法的源码文件 +2. `request => fileUpload.js` 七牛云上传和服务器上传的源码文件 +3. `request => index.js` 输出方法的文件 +4. `request => qiniuUploader.js` 七牛云官方上传文件 +5. `requestConfig.js` 请求配置文件(具体看代码) + +### 在main.js引入并挂在Vue上 +``` +import $http from '@/zhouWei-request/requestConfig'; +Vue.prototype.$http = $http; +``` + +### 通用请求方法(此方法不支持文件上传和JSONP) +``` +this.$http.request({ + url: 'aid/region', + method: "GET", // POST、GET、PUT、DELETE,具体说明查看官方文档 + data: {pid:0}, + timeout: 30000, // 默认 30000 说明:超时时间,单位 ms,具体说明查看官方文档 + dataType: "json", // 默认 json 说明:如果设为 json,会尝试对返回的数据做一次 JSON.parse,具体说明查看官方文档 + responseType: "text", // 默认 text 说明:设置响应的数据类型。合法值:text、arraybuffer,具体说明查看官方文档 + withCredentials: false, // 默认 false 说明:跨域请求时是否携带凭证(cookies),具体说明查看官方文档 + isPrompt: true,//(默认 true 说明:本接口抛出的错误是否提示) + load: true,//(默认 true 说明:本接口是否提示加载动画) + header: { //默认 无 说明:请求头 + 'Content-Type': 'application/json' + }, + isFactory: true, //(默认 true 说明:本接口是否调用公共的数据处理方法,设置false后isPrompt参数将失去作用) +}).then(function (response) { + //这里只会在接口是成功状态返回 +}).catch(function (error) { + //这里只会在接口是失败状态返回,不需要去处理错误提示 + console.log(error); +}); +``` + +### get请求 正常写法 +``` +this.$http.get('aid/region',{pid:0}). +then(function (response) { + //这里只会在接口是成功状态返回 +}).catch(function (error) { + //这里只会在接口是失败状态返回,不需要去处理错误提示 + console.log(error); +}); +``` + +### post请求 async写法 +``` +async request(){ + let data = await this.$http.post('aid/region',{pid:0}); + console.log(data); +} +``` + +### 其他功能配置项 +``` +let data = await this.$http.post( + 'http://www.aaa.com/aid/region', //可以直接放链接(将不启用全局定义域名) + { + pid:0 + }, + { + isPrompt: true,//(默认 true 说明:本接口抛出的错误是否提示) + load: true,//(默认 true 说明:本接口是否提示加载动画) + header: { //默认 无 说明:请求头 + 'Content-Type': 'application/json' + }, + isFactory: true //(默认 true 说明:本接口是否调用公共的数据处理方法,设置false后isPrompt参数将失去作用) + } +); +``` + +### 本地服务器图片上传(支持多张上传) +``` +this.$http.urlImgUpload('flie/upload',{ + name:"后台接受文件key名称", //默认 file + count:"最大选择数",//默认 9 + sizeType:"选择压缩图原图,默认两个都选",//默认 ['original', 'compressed'] + sourceType:"选择相机拍照或相册上传 默认两个都选",//默认 ['album','camera'] + data:"而外参数" //可不填, + onEachUpdate: res => { + console.log("单张上传成功返回:",res); + }, + onProgressUpdate: res => { + console.log("上传进度返回:",res); + } +},{ + isPrompt: true,//(默认 true 说明:本接口抛出的错误是否提示) + load: true,//(默认 true 说明:本接口是否提示加载动画) + header: { //默认 无 说明:请求头 + 'Content-Type': 'application/json' + }, + isFactory: true, //(默认 true 说明:本接口是否调用公共的数据处理方法,设置false后isPrompt参数奖失去作用) + maxSize: 300000 //(默认 无 说明:上传的文件最大字节数限制,默认不限制) +}).then(res => { + console.log("全部上传完返回结果:",res); +}); +``` +### 本地服务器文件上传(支持多张上传) +``` +this.$http.urlFileUpload("flie/upload",{ + files:[], // 必填 临时文件路径 + data:"向服务器传递的参数", //可不填 + name:"后台接受文件key名称", //默认 file + onEachUpdate: res => { + console.log("单张上传成功返回:",res); + }, + onProgressUpdate: res => { + console.log("上传进度返回:",res); + } + }, + { + isPrompt: true,//(默认 true 说明:本接口抛出的错误是否提示) + load: true,//(默认 true 说明:本接口是否提示加载动画) + header: { //默认 无 说明:请求头 + 'Content-Type': 'application/json' + }, + isFactory: true, //(默认 true 说明:本接口是否调用公共的数据处理方法,设置false后isPrompt参数奖失去作用) + maxSize: 300000 //(默认 无 说明:上传的文件最大字节数限制,默认不限制) + }).then(res => { + console.log("全部上传完返回结果:",res); + }); +``` + +### 七牛云图片上传(支持多张上传) +``` +this.$http.qnImgUpload({ + count:"最大选择数", // 默认 9 + sizeType:"选择压缩图原图,默认两个都选", // 默认 ['original', 'compressed'] + sourceType:"选择相机拍照或相册上传 默认两个都选", // 默认 ['album','camera'] + onEachUpdate: res => { + console.log("单张上传成功返回:",res); + }, + onProgressUpdate: res => { + console.log("上传进度返回:",res); + } + }, + { + load: true, //(默认 true 说明:本接口是否提示加载动画) + maxSize: 300000 //(默认 无 说明:上传的文件最大字节数限制,默认不限制) + }).then(res => { + console.log("全部上传完返回结果:",res); + }); +``` + +### 七牛云文件上传(支持多张上传) +``` +this.$http.qnFileUpload( + { + files:[], // 必填 临时文件路径 + onEachUpdate: res => { + console.log("单张上传成功返回:",res); + }, + onProgressUpdate: res => { + console.log("上传进度返回:",res); + } + }, + { + load: true, //(默认 true 说明:本接口是否提示加载动画) + maxSize: 300000 //(默认 无 说明:上传的文件最大字节数限制,默认不限制) + }).then(res => { + console.log("全部上传完返回结果:",res); + }); +``` +### jsonp 跨域请求(只支持H5) +``` +let data = await this.$http.jsonp('http://www.aaa.com/aid/region',{pid:0}); +``` diff --git a/supervise-uniapp/static/app-plus/mp-html/js/handler.js b/supervise-uniapp/static/app-plus/mp-html/js/handler.js deleted file mode 100644 index 92838327..00000000 --- a/supervise-uniapp/static/app-plus/mp-html/js/handler.js +++ /dev/null @@ -1,224 +0,0 @@ -'use strict' - -// 等待初始化完毕 -document.addEventListener('UniAppJSBridgeReady', () => { - document.body.onclick = function () { - return uni.postMessage({ - data: { - action: 'onClick' - } - }) - } - - uni.postMessage({ - data: { - action: 'onJSBridgeReady' - } - }) -}) -let options -let medias = [] -/** - * @description 获取标签的所有属性 - * @param {Element} ele - */ - -function getAttrs(ele) { - const attrs = Object.create(null) - - for (let i = ele.attributes.length; i--;) { - attrs[ele.attributes[i].name] = ele.attributes[i].value - } - - return attrs -} -/** - * @description 图片加载出错 - */ - -function onImgError() { - if (options[1]) { - this.src = options[1] - this.onerror = null - } // 取消监听点击 - - this.onclick = null - this.ontouchstart = null - uni.postMessage({ - data: { - action: 'onError', - source: 'img', - attrs: getAttrs(this) - } - }) -} -/** - * @description 创建 dom 结构 - * @param {object[]} nodes 节点数组 - * @param {Element} parent 父节点 - * @param {string} namespace 命名空间 - */ - -function createDom(nodes, parent, namespace) { - const _loop = function _loop(i) { - const node = nodes[i] - let ele = void 0 - - if (!node.type || node.type == 'node') { - let { name } = node // svg 需要设置 namespace - - if (name == 'svg') namespace = 'http://www.w3.org/2000/svg' - if (name == 'html' || name == 'body') name = 'div' // 创建标签 - - if (!namespace) ele = document.createElement(name); else ele = document.createElementNS(namespace, name) // 设置属性 - - for (const item in node.attrs) { - ele.setAttribute(item, node.attrs[item]) - } // 递归创建子节点 - - if (node.children) createDom(node.children, ele, namespace) // 处理图片 - - if (name == 'img') { - if (!ele.src && ele.getAttribute('data-src')) ele.src = ele.getAttribute('data-src') - - if (!node.attrs.ignore) { - // 监听图片点击事件 - ele.onclick = function (e) { - e.stopPropagation() - uni.postMessage({ - data: { - action: 'onImgTap', - attrs: getAttrs(this) - } - }) - } - } - - if (options[2]) { - image = new Image() - image.src = ele.src - ele.src = options[2] - - image.onload = function () { - ele.src = this.src - } - - image.onerror = function () { - ele.onerror() - } - } - - ele.onerror = onImgError - } // 处理链接 - else if (name == 'a') { - ele.addEventListener('click', function (e) { - e.stopPropagation() - e.preventDefault() // 阻止默认跳转 - - const href = this.getAttribute('href') - let offset - if (href && href[0] == '#') offset = (document.getElementById(href.substr(1)) || {}).offsetTop - uni.postMessage({ - data: { - action: 'onLinkTap', - attrs: getAttrs(this), - offset - } - }) - }, true) - } // 处理音视频 - else if (name == 'video' || name == 'audio') { - medias.push(ele) - - if (!node.attrs.autoplay) { - if (!node.attrs.controls) ele.setAttribute('controls', 'true') // 空白图占位 - - if (!node.attrs.poster) ele.setAttribute('poster', "data:image/svg+xml;utf8,") - } - - if (options[3]) { - ele.onplay = function () { - for (let _i = 0; _i < medias.length; _i++) { - if (medias[_i] != this) medias[_i].pause() - } - } - } - - ele.onerror = function () { - uni.postMessage({ - data: { - action: 'onError', - source: name, - attrs: getAttrs(this) - } - }) - } - } // 处理表格 - else if (name == 'table' && options[4] && !ele.style.cssText.includes('inline')) { - const div = document.createElement('div') - div.style.overflow = 'auto' - div.appendChild(ele) - ele = div - } else if (name == 'svg') namespace = void 0 - } else ele = document.createTextNode(node.text.replace(/&/g, '&')) - - parent.appendChild(ele) - } - - for (let i = 0; i < nodes.length; i++) { - var image - - _loop(i) - } -} // 设置 html 内容 - -window.setContent = function (nodes, opts, append) { - const ele = document.getElementById('content') // 背景颜色 - - if (opts[0]) document.body.bgColor = opts[0] // 长按复制 - - if (!opts[5]) ele.style.userSelect = 'none' - - if (!append) { - ele.innerHTML = '' // 不追加则先清空 - - medias = [] - } - - options = opts - const fragment = document.createDocumentFragment() - createDom(nodes, fragment) - ele.appendChild(fragment) // 触发事件 - - let height = ele.scrollHeight - uni.postMessage({ - data: { - action: 'onLoad', - height - } - }) - clearInterval(window.timer) - let ready = false - window.timer = setInterval(() => { - if (ele.scrollHeight != height) { - height = ele.scrollHeight - uni.postMessage({ - data: { - action: 'onHeightChange', - height - } - }) - } else if (!ready) { - ready = true - uni.postMessage({ - data: { - action: 'onReady' - } - }) - } - }, 350) -} // 回收计时器 - -window.onunload = function () { - clearInterval(window.timer) -} diff --git a/supervise-uniapp/static/app-plus/mp-html/js/uni.webview.min.js b/supervise-uniapp/static/app-plus/mp-html/js/uni.webview.min.js deleted file mode 100644 index 518332dd..00000000 --- a/supervise-uniapp/static/app-plus/mp-html/js/uni.webview.min.js +++ /dev/null @@ -1,19 +0,0 @@ -!(function (e, n) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = n() : typeof define === 'function' && define.amd ? define(n) : (e = e || self).uni = n() }(this, (() => { - 'use strict' - - try { const e = {}; Object.defineProperty(e, 'passive', { get() { !0 } }), window.addEventListener('test-passive', null, e) } catch (e) {} const n = Object.prototype.hasOwnProperty; function t(e, t) { return n.call(e, t) } const i = []; const a = function (e, n) { const t = { options: { timestamp: +new Date() }, name: e, arg: n }; if (window.__dcloud_weex_postMessage || window.__dcloud_weex_) { if (e === 'postMessage') { const a = { data: [n] }; return window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessage(a) : window.__dcloud_weex_.postMessage(JSON.stringify(a)) } const o = { type: 'WEB_INVOKE_APPSERVICE', args: { data: t, webviewIds: i } }; window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessageToService(o) : window.__dcloud_weex_.postMessageToService(JSON.stringify(o)) } if (!window.plus) return window.parent.postMessage({ type: 'WEB_INVOKE_APPSERVICE', data: t, pageId: '' }, '*'); if (i.length === 0) { const r = plus.webview.currentWebview(); if (!r) throw new Error('plus.webview.currentWebview() is undefined'); const d = r.parent(); let s = ''; s = d ? d.id : r.id, i.push(s) } if (plus.webview.getWebviewById('__uniapp__service'))plus.webview.postMessageToUniNView({ type: 'WEB_INVOKE_APPSERVICE', args: { data: t, webviewIds: i } }, '__uniapp__service'); else { const w = JSON.stringify(t); plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat('WEB_INVOKE_APPSERVICE', '",').concat(w, ',').concat(JSON.stringify(i), ');')) } }; const o = { - navigateTo() { const e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}; const n = e.url; a('navigateTo', { url: encodeURI(n) }) }, navigateBack() { const e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}; const n = e.delta; a('navigateBack', { delta: parseInt(n) || 1 }) }, switchTab() { const e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}; const n = e.url; a('switchTab', { url: encodeURI(n) }) }, reLaunch() { const e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}; const n = e.url; a('reLaunch', { url: encodeURI(n) }) }, redirectTo() { const e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}; const n = e.url; a('redirectTo', { url: encodeURI(n) }) }, getEnv(e) { window.plus ? e({ plus: !0 }) : e({ h5: !0 }) }, postMessage() { const e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}; a('postMessage', e.data || {}) } - }; const r = /uni-app/i.test(navigator.userAgent); const d = /Html5Plus/i.test(navigator.userAgent); const s = /complete|loaded|interactive/; const w = window.my && navigator.userAgent.indexOf('AlipayClient') > -1; const u = window.swan && window.swan.webView && /swan/i.test(navigator.userAgent); const c = window.qq && window.qq.miniProgram && /QQ/i.test(navigator.userAgent) && /miniProgram/i.test(navigator.userAgent); const g = window.tt && window.tt.miniProgram && /toutiaomicroapp/i.test(navigator.userAgent); const v = window.wx && window.wx.miniProgram && /micromessenger/i.test(navigator.userAgent) && /miniProgram/i.test(navigator.userAgent); const p = window.qa && /quickapp/i.test(navigator.userAgent); for (var l, _ = function () { window.UniAppJSBridge = !0, document.dispatchEvent(new CustomEvent('UniAppJSBridgeReady', { bubbles: !0, cancelable: !0 })) }, f = [function (e) { if (r || d) return window.__dcloud_weex_postMessage || window.__dcloud_weex_ ? document.addEventListener('DOMContentLoaded', e) : window.plus && s.test(document.readyState) ? setTimeout(e, 0) : document.addEventListener('plusready', e), o }, function (e) { if (v) return window.WeixinJSBridge && window.WeixinJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener('WeixinJSBridgeReady', e), window.wx.miniProgram }, function (e) { if (c) return window.QQJSBridge && window.QQJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener('QQJSBridgeReady', e), window.qq.miniProgram }, function (e) { - if (w) { - document.addEventListener('DOMContentLoaded', e); const n = window.my; return { - navigateTo: n.navigateTo, navigateBack: n.navigateBack, switchTab: n.switchTab, reLaunch: n.reLaunch, redirectTo: n.redirectTo, postMessage: n.postMessage, getEnv: n.getEnv - } - } - }, function (e) { if (u) return document.addEventListener('DOMContentLoaded', e), window.swan.webView }, function (e) { if (g) return document.addEventListener('DOMContentLoaded', e), window.tt.miniProgram }, function (e) { - if (p) { - window.QaJSBridge && window.QaJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener('QaJSBridgeReady', e); const n = window.qa; return { - navigateTo: n.navigateTo, navigateBack: n.navigateBack, switchTab: n.switchTab, reLaunch: n.reLaunch, redirectTo: n.redirectTo, postMessage: n.postMessage, getEnv: n.getEnv - } - } - }, function (e) { return document.addEventListener('DOMContentLoaded', e), o }], m = 0; m < f.length && !(l = f[m](_)); m++);l || (l = {}); const E = typeof uni !== 'undefined' ? uni : {}; if (!E.navigateTo) for (const b in l)t(l, b) && (E[b] = l[b]); return E.webView = l, E -}))) diff --git a/supervise-uniapp/static/app-plus/mp-html/local.html b/supervise-uniapp/static/app-plus/mp-html/local.html deleted file mode 100644 index f78d703c..00000000 --- a/supervise-uniapp/static/app-plus/mp-html/local.html +++ /dev/null @@ -1 +0,0 @@ -
\ No newline at end of file diff --git a/supervise-uniapp/static/baseIcon/zy.png b/supervise-uniapp/static/baseIcon/zy.png new file mode 100644 index 00000000..4cc864e1 Binary files /dev/null and b/supervise-uniapp/static/baseIcon/zy.png differ diff --git a/supervise-uniapp/static/bottom-icon/add_normal.png b/supervise-uniapp/static/bottom-icon/add_normal.png deleted file mode 100644 index 84a1ee99..00000000 Binary files a/supervise-uniapp/static/bottom-icon/add_normal.png and /dev/null differ diff --git a/supervise-uniapp/static/bottom-icon/add_press.png b/supervise-uniapp/static/bottom-icon/add_press.png deleted file mode 100644 index f5b2943b..00000000 Binary files a/supervise-uniapp/static/bottom-icon/add_press.png and /dev/null differ diff --git a/supervise-uniapp/static/bottom-icon/find_normal.png b/supervise-uniapp/static/bottom-icon/find_normal.png deleted file mode 100644 index 4673793b..00000000 Binary files a/supervise-uniapp/static/bottom-icon/find_normal.png and /dev/null differ diff --git a/supervise-uniapp/static/bottom-icon/find_press.png b/supervise-uniapp/static/bottom-icon/find_press.png deleted file mode 100644 index bd87c110..00000000 Binary files a/supervise-uniapp/static/bottom-icon/find_press.png and /dev/null differ diff --git a/supervise-uniapp/static/bottom-icon/gongzuotai.png b/supervise-uniapp/static/bottom-icon/gongzuotai.png new file mode 100644 index 00000000..d4ca3f41 Binary files /dev/null and b/supervise-uniapp/static/bottom-icon/gongzuotai.png differ diff --git a/supervise-uniapp/static/bottom-icon/gongzuotai1.png b/supervise-uniapp/static/bottom-icon/gongzuotai1.png new file mode 100644 index 00000000..9a43e8f0 Binary files /dev/null and b/supervise-uniapp/static/bottom-icon/gongzuotai1.png differ diff --git a/supervise-uniapp/static/bottom-icon/mine_normal.png b/supervise-uniapp/static/bottom-icon/mine_normal.png deleted file mode 100644 index a468441c..00000000 Binary files a/supervise-uniapp/static/bottom-icon/mine_normal.png and /dev/null differ diff --git a/supervise-uniapp/static/bottom-icon/mine_press.png b/supervise-uniapp/static/bottom-icon/mine_press.png deleted file mode 100644 index 1f6779a0..00000000 Binary files a/supervise-uniapp/static/bottom-icon/mine_press.png and /dev/null differ diff --git a/supervise-uniapp/static/bottom-icon/wode.png b/supervise-uniapp/static/bottom-icon/wode.png new file mode 100644 index 00000000..05c0dbee Binary files /dev/null and b/supervise-uniapp/static/bottom-icon/wode.png differ diff --git a/supervise-uniapp/static/bottom-icon/wode1.png b/supervise-uniapp/static/bottom-icon/wode1.png new file mode 100644 index 00000000..c997bfee Binary files /dev/null and b/supervise-uniapp/static/bottom-icon/wode1.png differ diff --git a/supervise-uniapp/static/bottom-icon/xiaoxi.png b/supervise-uniapp/static/bottom-icon/xiaoxi.png new file mode 100644 index 00000000..10b0323e Binary files /dev/null and b/supervise-uniapp/static/bottom-icon/xiaoxi.png differ diff --git a/supervise-uniapp/static/bottom-icon/xiaoxi1.png b/supervise-uniapp/static/bottom-icon/xiaoxi1.png new file mode 100644 index 00000000..07d4e4ba Binary files /dev/null and b/supervise-uniapp/static/bottom-icon/xiaoxi1.png differ diff --git a/supervise-uniapp/static/c1.png b/supervise-uniapp/static/c1.png deleted file mode 100644 index 9d38fdc4..00000000 Binary files a/supervise-uniapp/static/c1.png and /dev/null differ diff --git a/supervise-uniapp/static/c2.png b/supervise-uniapp/static/c2.png deleted file mode 100644 index ce956d76..00000000 Binary files a/supervise-uniapp/static/c2.png and /dev/null differ diff --git a/supervise-uniapp/static/c3.png b/supervise-uniapp/static/c3.png deleted file mode 100644 index 216202ad..00000000 Binary files a/supervise-uniapp/static/c3.png and /dev/null differ diff --git a/supervise-uniapp/static/c4.png b/supervise-uniapp/static/c4.png deleted file mode 100644 index fb8b4770..00000000 Binary files a/supervise-uniapp/static/c4.png and /dev/null differ diff --git a/supervise-uniapp/static/c5.png b/supervise-uniapp/static/c5.png deleted file mode 100644 index 310bfb12..00000000 Binary files a/supervise-uniapp/static/c5.png and /dev/null differ diff --git a/supervise-uniapp/static/c6.png b/supervise-uniapp/static/c6.png deleted file mode 100644 index c3c45d88..00000000 Binary files a/supervise-uniapp/static/c6.png and /dev/null differ diff --git a/supervise-uniapp/static/c7.png b/supervise-uniapp/static/c7.png deleted file mode 100644 index a1e73908..00000000 Binary files a/supervise-uniapp/static/c7.png and /dev/null differ diff --git a/supervise-uniapp/static/c8.png b/supervise-uniapp/static/c8.png deleted file mode 100644 index c32633c0..00000000 Binary files a/supervise-uniapp/static/c8.png and /dev/null differ diff --git a/supervise-uniapp/static/c9.png b/supervise-uniapp/static/c9.png deleted file mode 100644 index 51bcf6a1..00000000 Binary files a/supervise-uniapp/static/c9.png and /dev/null differ diff --git a/supervise-uniapp/static/common/js/touch-emulator.js b/supervise-uniapp/static/common/js/touch-emulator.js deleted file mode 100644 index b90c8acc..00000000 --- a/supervise-uniapp/static/common/js/touch-emulator.js +++ /dev/null @@ -1,363 +0,0 @@ -(function (window, document, exportName, undefined) { - "use strict"; - - var isMultiTouch = false; - var multiTouchStartPos; - var eventTarget; - var touchElements = {}; - - // polyfills - if (!document.createTouch) { - document.createTouch = function (view, target, identifier, pageX, pageY, screenX, screenY, clientX, clientY) { - // auto set - if (clientX == undefined || clientY == undefined) { - clientX = pageX - window.pageXOffset; - clientY = pageY - window.pageYOffset; - } - - return new Touch(target, identifier, { - pageX: pageX, - pageY: pageY, - screenX: screenX, - screenY: screenY, - clientX: clientX, - clientY: clientY - }); - }; - } - - if (!document.createTouchList) { - document.createTouchList = function () { - var touchList = new TouchList(); - for (var i = 0; i < arguments.length; i++) { - touchList[i] = arguments[i]; - } - touchList.length = arguments.length; - return touchList; - }; - } - - /** - * create an touch point - * @constructor - * @param target - * @param identifier - * @param pos - * @param deltaX - * @param deltaY - * @returns {Object} touchPoint - */ - function Touch(target, identifier, pos, deltaX, deltaY) { - deltaX = deltaX || 0; - deltaY = deltaY || 0; - - this.identifier = identifier; - this.target = target; - this.clientX = pos.clientX + deltaX; - this.clientY = pos.clientY + deltaY; - this.screenX = pos.screenX + deltaX; - this.screenY = pos.screenY + deltaY; - this.pageX = pos.pageX + deltaX; - this.pageY = pos.pageY + deltaY; - } - - /** - * create empty touchlist with the methods - * @constructor - * @returns touchList - */ - function TouchList() { - var touchList = []; - - touchList.item = function (index) { - return this[index] || null; - }; - - // specified by Mozilla - touchList.identifiedTouch = function (id) { - return this[id + 1] || null; - }; - - return touchList; - } - - - /** - * Simple trick to fake touch event support - * this is enough for most libraries like Modernizr and Hammer - */ - function fakeTouchSupport() { - var objs = [window, document.documentElement]; - var props = ['ontouchstart', 'ontouchmove', 'ontouchcancel', 'ontouchend']; - - for (var o = 0; o < objs.length; o++) { - for (var p = 0; p < props.length; p++) { - if (objs[o] && objs[o][props[p]] == undefined) { - objs[o][props[p]] = null; - } - } - } - } - - /** - * we don't have to emulate on a touch device - * @returns {boolean} - */ - function hasTouchSupport() { - return ("ontouchstart" in window) || // touch events - (window.Modernizr && window.Modernizr.touch) || // modernizr - (navigator.msMaxTouchPoints || navigator.maxTouchPoints) > 2; // pointer events - } - - /** - * disable mouseevents on the page - * @param ev - */ - function preventMouseEvents(ev) { - // 注释启用默认事件 - // ev.preventDefault(); - // ev.stopPropagation(); - } - - /** - * only trigger touches when the left mousebutton has been pressed - * @param touchType - * @returns {Function} - */ - function onMouse(touchType) { - return function (ev) { - // prevent mouse events - preventMouseEvents(ev); - - if (ev.which !== 1) { - return; - } - - // The EventTarget on which the touch point started when it was first placed on the surface, - // even if the touch point has since moved outside the interactive area of that element. - // also, when the target doesnt exist anymore, we update it - if (ev.type == 'mousedown' || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)) { - eventTarget = ev.target; - } - - // shiftKey has been lost, so trigger a touchend - if (isMultiTouch && !ev.shiftKey) { - triggerTouch('touchend', ev); - isMultiTouch = false; - } - - triggerTouch(touchType, ev); - - // we're entering the multi-touch mode! - if (!isMultiTouch && ev.shiftKey) { - isMultiTouch = true; - multiTouchStartPos = { - pageX: ev.pageX, - pageY: ev.pageY, - clientX: ev.clientX, - clientY: ev.clientY, - screenX: ev.screenX, - screenY: ev.screenY - }; - triggerTouch('touchstart', ev); - } - - // reset - if (ev.type == 'mouseup') { - multiTouchStartPos = null; - isMultiTouch = false; - eventTarget = null; - } - } - } - - /** - * trigger a touch event - * @param eventName - * @param mouseEv - */ - function triggerTouch(eventName, mouseEv) { - var touchEvent = document.createEvent('Event'); - touchEvent.initEvent(eventName, true, true); - - touchEvent.altKey = mouseEv.altKey; - touchEvent.ctrlKey = mouseEv.ctrlKey; - touchEvent.metaKey = mouseEv.metaKey; - touchEvent.shiftKey = mouseEv.shiftKey; - - touchEvent.touches = getActiveTouches(mouseEv, eventName); - touchEvent.targetTouches = getActiveTouches(mouseEv, eventName); - touchEvent.changedTouches = getChangedTouches(mouseEv, eventName); - - eventTarget.dispatchEvent(touchEvent); - } - - /** - * create a touchList based on the mouse event - * @param mouseEv - * @returns {TouchList} - */ - function createTouchList(mouseEv) { - var touchList = new TouchList(); - - if (isMultiTouch) { - var f = TouchEmulator.multiTouchOffset; - var deltaX = multiTouchStartPos.pageX - mouseEv.pageX; - var deltaY = multiTouchStartPos.pageY - mouseEv.pageY; - - touchList.push(new Touch(eventTarget, 1, multiTouchStartPos, (deltaX * -1) - f, (deltaY * -1) + f)); - touchList.push(new Touch(eventTarget, 2, multiTouchStartPos, deltaX + f, deltaY - f)); - } else { - touchList.push(new Touch(eventTarget, 1, mouseEv, 0, 0)); - } - - return touchList; - } - - /** - * receive all active touches - * @param mouseEv - * @returns {TouchList} - */ - function getActiveTouches(mouseEv, eventName) { - // empty list - if (mouseEv.type == 'mouseup') { - return new TouchList(); - } - - var touchList = createTouchList(mouseEv); - if (isMultiTouch && mouseEv.type != 'mouseup' && eventName == 'touchend') { - touchList.splice(1, 1); - } - return touchList; - } - - /** - * receive a filtered set of touches with only the changed pointers - * @param mouseEv - * @param eventName - * @returns {TouchList} - */ - function getChangedTouches(mouseEv, eventName) { - var touchList = createTouchList(mouseEv); - - // we only want to return the added/removed item on multitouch - // which is the second pointer, so remove the first pointer from the touchList - // - // but when the mouseEv.type is mouseup, we want to send all touches because then - // no new input will be possible - if (isMultiTouch && mouseEv.type != 'mouseup' && - (eventName == 'touchstart' || eventName == 'touchend')) { - touchList.splice(0, 1); - } - - return touchList; - } - - /** - * show the touchpoints on the screen - */ - function showTouches(ev) { - var touch, i, el, styles; - - // first all visible touches - for (i = 0; i < ev.touches.length; i++) { - touch = ev.touches[i]; - el = touchElements[touch.identifier]; - if (!el) { - el = touchElements[touch.identifier] = document.createElement("div"); - document.body.appendChild(el); - } - - styles = TouchEmulator.template(touch); - for (var prop in styles) { - el.style[prop] = styles[prop]; - } - } - - // remove all ended touches - if (ev.type == 'touchend' || ev.type == 'touchcancel') { - for (i = 0; i < ev.changedTouches.length; i++) { - touch = ev.changedTouches[i]; - el = touchElements[touch.identifier]; - if (el) { - el.parentNode.removeChild(el); - delete touchElements[touch.identifier]; - } - } - } - } - - /** - * TouchEmulator initializer - */ - function TouchEmulator() { - if (hasTouchSupport()) { - return; - } - - fakeTouchSupport(); - - window.addEventListener("mousedown", onMouse('touchstart'), true); - window.addEventListener("mousemove", onMouse('touchmove'), true); - window.addEventListener("mouseup", onMouse('touchend'), true); - - window.addEventListener("mouseenter", preventMouseEvents, true); - window.addEventListener("mouseleave", preventMouseEvents, true); - window.addEventListener("mouseout", preventMouseEvents, true); - window.addEventListener("mouseover", preventMouseEvents, true); - - // it uses itself! - window.addEventListener("touchstart", showTouches, true); - window.addEventListener("touchmove", showTouches, true); - window.addEventListener("touchend", showTouches, true); - window.addEventListener("touchcancel", showTouches, true); - } - - // start distance when entering the multitouch mode - TouchEmulator.multiTouchOffset = 75; - - /** - * css template for the touch rendering - * @param touch - * @returns object - */ - TouchEmulator.template = function (touch) { - var size = 0; - var transform = 'translate(' + (touch.clientX - (size / 2)) + 'px, ' + (touch.clientY - (size / 2)) + 'px)'; - return { - position: 'fixed', - left: 0, - top: 0, - background: '#fff', - border: 'solid 1px #999', - opacity: .6, - borderRadius: '100%', - height: size + 'px', - width: size + 'px', - padding: 0, - margin: 0, - display: 'block', - overflow: 'hidden', - pointerEvents: 'none', - webkitUserSelect: 'none', - mozUserSelect: 'none', - userSelect: 'none', - webkitTransform: transform, - mozTransform: transform, - transform: transform, - zIndex: 100 - } - }; - - // export - if (typeof define == "function" && define.amd) { - define(function () { - return TouchEmulator; - }); - } else if (typeof module != "undefined" && module.exports) { - module.exports = TouchEmulator; - } else { - window[exportName] = TouchEmulator; - } -})(window, document, "TouchEmulator"); \ No newline at end of file diff --git a/supervise-uniapp/static/ic_ar.png b/supervise-uniapp/static/ic_ar.png new file mode 100644 index 00000000..4c05da85 Binary files /dev/null and b/supervise-uniapp/static/ic_ar.png differ diff --git a/supervise-uniapp/static/loginIcon/isShow.png b/supervise-uniapp/static/loginIcon/isShow.png new file mode 100644 index 00000000..8bdd09f6 Binary files /dev/null and b/supervise-uniapp/static/loginIcon/isShow.png differ diff --git a/supervise-uniapp/static/loginIcon/mm.png b/supervise-uniapp/static/loginIcon/mm.png new file mode 100644 index 00000000..050ebd4e Binary files /dev/null and b/supervise-uniapp/static/loginIcon/mm.png differ diff --git a/supervise-uniapp/static/loginIcon/notShow.png b/supervise-uniapp/static/loginIcon/notShow.png new file mode 100644 index 00000000..3ae849ed Binary files /dev/null and b/supervise-uniapp/static/loginIcon/notShow.png differ diff --git a/supervise-uniapp/static/loginIcon/sjh.png b/supervise-uniapp/static/loginIcon/sjh.png new file mode 100644 index 00000000..b0ee8f4f Binary files /dev/null and b/supervise-uniapp/static/loginIcon/sjh.png differ diff --git a/supervise-uniapp/static/loginIcon/wgx.png b/supervise-uniapp/static/loginIcon/wgx.png new file mode 100644 index 00000000..832d6e86 Binary files /dev/null and b/supervise-uniapp/static/loginIcon/wgx.png differ diff --git a/supervise-uniapp/static/loginIcon/wx.png b/supervise-uniapp/static/loginIcon/wx.png new file mode 100644 index 00000000..fccb8c2b Binary files /dev/null and b/supervise-uniapp/static/loginIcon/wx.png differ diff --git a/supervise-uniapp/static/loginIcon/xz.png b/supervise-uniapp/static/loginIcon/xz.png new file mode 100644 index 00000000..5e7a2919 Binary files /dev/null and b/supervise-uniapp/static/loginIcon/xz.png differ diff --git a/supervise-uniapp/static/logo.png b/supervise-uniapp/static/logo.png index eb8307fb..a95dbf81 100644 Binary files a/supervise-uniapp/static/logo.png and b/supervise-uniapp/static/logo.png differ diff --git a/supervise-uniapp/static/uni.png b/supervise-uniapp/static/uni.png deleted file mode 100644 index 8e3a80f4..00000000 Binary files a/supervise-uniapp/static/uni.png and /dev/null differ diff --git a/supervise-uniapp/static/uniui.png b/supervise-uniapp/static/uniui.png deleted file mode 100644 index 710f9246..00000000 Binary files a/supervise-uniapp/static/uniui.png and /dev/null differ diff --git a/supervise-uniapp/static/uview/common/favicon.ico b/supervise-uniapp/static/uview/common/favicon.ico deleted file mode 100644 index e0af3681..00000000 Binary files a/supervise-uniapp/static/uview/common/favicon.ico and /dev/null differ diff --git a/supervise-uniapp/static/uview/common/gray-logo.png b/supervise-uniapp/static/uview/common/gray-logo.png deleted file mode 100644 index 21a69949..00000000 Binary files a/supervise-uniapp/static/uview/common/gray-logo.png and /dev/null differ diff --git a/supervise-uniapp/static/uview/common/logo.png b/supervise-uniapp/static/uview/common/logo.png deleted file mode 100644 index 05b3aed3..00000000 Binary files a/supervise-uniapp/static/uview/common/logo.png and /dev/null differ diff --git a/supervise-uniapp/static/uview/example/component.png b/supervise-uniapp/static/uview/example/component.png deleted file mode 100644 index 9464b237..00000000 Binary files a/supervise-uniapp/static/uview/example/component.png and /dev/null differ diff --git a/supervise-uniapp/static/uview/example/component_select.png b/supervise-uniapp/static/uview/example/component_select.png deleted file mode 100644 index 79efb5b5..00000000 Binary files a/supervise-uniapp/static/uview/example/component_select.png and /dev/null differ diff --git a/supervise-uniapp/static/uview/example/js.png b/supervise-uniapp/static/uview/example/js.png deleted file mode 100644 index beb0dc7b..00000000 Binary files a/supervise-uniapp/static/uview/example/js.png and /dev/null differ diff --git a/supervise-uniapp/static/uview/example/js_bak.png b/supervise-uniapp/static/uview/example/js_bak.png deleted file mode 100644 index d280e3da..00000000 Binary files a/supervise-uniapp/static/uview/example/js_bak.png and /dev/null differ diff --git a/supervise-uniapp/static/uview/example/js_select.png b/supervise-uniapp/static/uview/example/js_select.png deleted file mode 100644 index e8309a41..00000000 Binary files a/supervise-uniapp/static/uview/example/js_select.png and /dev/null differ diff --git a/supervise-uniapp/static/uview/example/template.png b/supervise-uniapp/static/uview/example/template.png deleted file mode 100644 index ff895b86..00000000 Binary files a/supervise-uniapp/static/uview/example/template.png and /dev/null differ diff --git a/supervise-uniapp/static/uview/example/template_select.png b/supervise-uniapp/static/uview/example/template_select.png deleted file mode 100644 index 90d66012..00000000 Binary files a/supervise-uniapp/static/uview/example/template_select.png and /dev/null differ diff --git a/supervise-uniapp/utils/requester.js b/supervise-uniapp/utils/requester.js index 4682b7b1..86476061 100644 --- a/supervise-uniapp/utils/requester.js +++ b/supervise-uniapp/utils/requester.js @@ -64,6 +64,8 @@ const request = (options) => { header: _opts.header, timeout: _opts.timeout || 60000, success: res => { + console.log("res>>>",res) + if (200 === res.statusCode) { let data = res.data if (_opts.catchError) { diff --git a/supervise-wx-mp/common/config.js b/supervise-wx-mp/common/config.js index 825b3c5d..9096ca2f 100644 --- a/supervise-wx-mp/common/config.js +++ b/supervise-wx-mp/common/config.js @@ -6,8 +6,8 @@ * loginTimeoutPage = "/pages/login/index", // 登录超时或失效的情况下,跳转到的登录页面 */ module.exports = { - // baseUrl: 'http://192.168.1.193:7009', - baseUrl: 'https://jianguan.yyundong.com', + baseUrl: 'http://192.168.1.193:7009', + // baseUrl: 'https://jianguan.yyundong.com', // baseUrl: 'http://jianguan.yyundong.com/api', tokenName: "Authorization", // 请求头中token的名字,与服务器端对应 loginTimeoutCode: "5001", // 登录超时或失效的情况下,服务器端返回的错误码 diff --git a/supervise-wx-mp/pages/index/demoReportKc - 副本.vue b/supervise-wx-mp/pages/index/demoReportKc - 副本.vue new file mode 100644 index 00000000..f16c4c1d --- /dev/null +++ b/supervise-wx-mp/pages/index/demoReportKc - 副本.vue @@ -0,0 +1,1228 @@ + + + + + \ No newline at end of file diff --git a/supervise-wx-mp/pages/index/demoReportKc.vue b/supervise-wx-mp/pages/index/demoReportKc.vue index f16c4c1d..bf08fa97 100644 --- a/supervise-wx-mp/pages/index/demoReportKc.vue +++ b/supervise-wx-mp/pages/index/demoReportKc.vue @@ -1,998 +1,85 @@ @@ -1151,14 +139,36 @@ components: {}, data() { return { - cover: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg', - avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png', - extraIcon: { - color: '#4cd964', - size: '22', - type: 'gear-filled' - } + date: "2023-06-25", + tableData1: [], + logInfo: { + title: "", + reportTime: "", + countAmount: "", + }, + tableData2: [], + logInfo2: { + countProductNumber: "", + countAmount: "", + }, + tableData3: [], + logInfo3: { + countProductNumber: "", + countAmount: "", + }, + + } + }, + onLoad(option) { + + // this.date = option.orderDate + + // console.log('1111', this.queryParams) + this.getData() + + + }, methods: { onClick(e) { @@ -1173,34 +183,80 @@ title: text, icon: 'none' }) - } + }, + getData() { + console.log('getData', this.date) + this.$api.getReportInventoryDayGather(this.date).then((resp) => { + console.log('1111>>>>>>', resp) + this.fileUrl = resp.downloadUrl + this.tableData1 = resp.list + this.logInfo = { + title: resp.title, + reportTime: resp.orderDate, + countAmount: resp.countAmount, + } + + }).catch(e => { + console.log('eeeee', e) + }) + + this.$api.getReportInventoryDayStore(this.date).then((resp) => { + console.log('2222>>>>>>', resp) + this.tableData2 = resp.list + this.logInfo2 = { + countProductNumber: resp.countProductNumber, + countAmount: resp.countAmount, + } + }).catch(e => { + console.log('eeeee', e) + }) + + // this.$api.getReportInventoryDayToStore(this.date).then((resp) => { + // console.log('3333>>>>>>', resp) + // this.tableData3 = resp.list + // this.logInfo3 = { + // countProductNumber: resp.countProductNumber, + // countAmount: resp.countAmount, + // } + // }).catch(e => { + // console.log('eeeee', e) + // }) + }, + } }