Home.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <view class="container">
  3. <view class="bannerBox">
  4. <swiper class="swiper" circular autoplay>
  5. <swiper-item class="swiperItem" v-for="(item, index) in bannerData" :key="index">
  6. <image class="swiperImg" :src="item"></image>
  7. </swiper-item>
  8. </swiper>
  9. </view>
  10. <view class="contentBox">
  11. <view class="operateBox">
  12. <view class="operateItemBox" v-for="(item, index) in industryData" :key="index">
  13. <view class="operateItem" @tap="toWrite(item)">
  14. <!-- <image :src="item.cellImgUrl" class="operateItemBGImg" mode="widthFix"></image> -->
  15. <image src="/static/logo.png" class="operateItemBGImg" mode="widthFix"></image>
  16. <text class="operateItemText">{{item.txtRemarks}}</text>
  17. </view>
  18. </view>
  19. <!-- <view class="operateItemBox">
  20. <view class="operateItem" @tap="toWrite({id: '08dd2e1f-94ff-4e70-8360-8e5c33425328'})">
  21. <image src="/static/logo.png" class="operateItemBGImg" mode="widthFix"></image>
  22. <text class="operateItemText">安全隐患排查治理信息系统</text>
  23. </view>
  24. </view> -->
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. var that;
  31. export default {
  32. options: {
  33. styleIsolation: 'isolated'
  34. },
  35. data() {
  36. return {
  37. openID: '',
  38. bannerData: [],
  39. industryData: [],
  40. latitude: '',
  41. longitude: ''
  42. }
  43. },
  44. methods: {
  45. getData(){
  46. that = this;
  47. that.onGetData();
  48. that.updateData();
  49. },
  50. // 父页面更新openID
  51. updateData(){
  52. that.openID = uni.getStorageSync('userInfo').openID;
  53. },
  54. onGetData(){
  55. that.$admin.reqDirect({
  56. method: 'GET',
  57. url: '/api/v1/Snapshot/home'
  58. }).then(res => {
  59. that.bannerData = res.banners;
  60. that.industryData = res.industrys;
  61. }, err => {
  62. that.$util.msg(err);
  63. })
  64. },
  65. getAuthorizeInfo(fun) {
  66. uni.authorize({
  67. scope: 'scope.userLocation',
  68. success() { // 允许授权
  69. that.getLocationInfo(fun);
  70. },
  71. fail() { // 拒绝授权
  72. that.openConfirm(fun);
  73. }
  74. })
  75. },
  76. // 获取地理位置
  77. getLocationInfo(fun) {
  78. uni.getLocation({
  79. type: 'gcj02',
  80. success: function(res) {
  81. that.latitude = res.latitude;
  82. that.longitude = res.longitude;
  83. typeof fun === 'function' && fun();
  84. }
  85. });
  86. },
  87. // 当用户第一次拒绝后再次请求授权
  88. openConfirm(fun) {
  89. uni.showModal({
  90. title: '请求授权当前位置',
  91. content: '需要获取您当前的所在城市,请确认授权',
  92. success: (res) => {
  93. if (res.confirm) {
  94. uni.openSetting({
  95. success(res) {
  96. if (res.authSetting['scope.userLocation']) {
  97. that.getLocationInfo(fun);
  98. } else {
  99. typeof fun === 'function' && fun();
  100. }
  101. }
  102. }); // 打开地图权限设置
  103. } else if (res.cancel) {
  104. uni.showToast({
  105. title: '你拒绝了授权,无法获得你所在城市信息',
  106. icon: 'none',
  107. duration: 1000,
  108. success() {
  109. typeof fun === 'function' && fun();
  110. }
  111. })
  112. }
  113. }
  114. });
  115. },
  116. // 不同类型隐患上报
  117. toWrite(obj) {
  118. // let strUrl = obj.pageUrl || 'comingSoon'
  119. // let strUrl = 'comingSoon'
  120. // let strUrl = '/pagesBase/Write/ReportHiddenDanger'
  121. // let strUrl = '/pagesBase/Write/LivelihoodFacts'
  122. // let strUrl = '/pagesBase/Write/WeldingOperations'
  123. let strUrl = '/pagesPointsBase/Points/Index'
  124. // let strUrl = 'navigateToMiniProgramByAppId?appId=wxc564149bc4d892f3&path=pages/index/index&type=WeldingOperations'
  125. // let strUrl = 'navigateToExternalLinks?externalUrl=https://zgyjglyzpt.cn'
  126. if (strUrl.indexOf("navigateToMiniProgramByAppId") !== -1){
  127. if(!strUrl || strUrl.split('?').length != 2 || strUrl.split('?')[1].split('&').length != 3){
  128. that.$util.msg('跳转地址配置错误!');
  129. }else {
  130. let appId = strUrl.split('?')[1].split('&')[0].split('=')[1] || '';
  131. let path = strUrl.split('?')[1].split('&')[1].split('=')[1] || '';
  132. let type = strUrl.split('?')[1].split('&')[2].split('=')[1] || '';
  133. if (type == 'WeldingOperations'){
  134. if (!that.openID) {
  135. that.$util.msg("请先登录", function(){
  136. uni.switchTab({
  137. url: "/pages/Index/Mine"
  138. })
  139. });
  140. return;
  141. }
  142. // path += '?openId=' + that.openID;
  143. uni.navigateToMiniProgram({
  144. appId: appId,
  145. path: path,
  146. extraData: {
  147. 'openId': that.openID
  148. },
  149. envVersion: 'release',
  150. fail(err) {
  151. that.$util.msg('您已取消打开');
  152. }
  153. })
  154. }else if (type == 'HomeworkReporte'){
  155. uni.navigateToMiniProgram({
  156. appId: appId,
  157. path: path,
  158. envVersion: 'release',
  159. fail(err) {
  160. that.$util.msg('您已取消打开');
  161. }
  162. })
  163. }
  164. }
  165. }else if (strUrl.indexOf("navigateToExternalLinks") !== -1){
  166. let externalUrl = strUrl.split('?')[1].split('=')[1];
  167. // that.getAuthorizeInfo(function(){
  168. uni.navigateTo({
  169. url: '/pages/ExternalLinks/Index?externalUrl=' + encodeURIComponent(externalUrl)
  170. })
  171. // });
  172. }else if (strUrl.indexOf("comingSoon") !== -1){
  173. that.$util.msg("功能即将上线,敬请期待!");
  174. }else {
  175. if (!that.openID) {
  176. that.$util.msg("请先登录", function(){
  177. uni.switchTab({
  178. url: "/pages/Index/Mine"
  179. })
  180. });
  181. return;
  182. }
  183. uni.navigateTo({
  184. url: strUrl + '?id=' + encodeURIComponent(obj.id)
  185. });
  186. }
  187. },
  188. }
  189. }
  190. </script>
  191. <style lang="less">
  192. .container {
  193. background-color: #fff;
  194. }
  195. .bannerBox {
  196. width: calc(100% - 40rpx);
  197. height: 300rpx;
  198. margin: 0 20rpx;
  199. border-radius: 20rpx;
  200. box-shadow: 0px 22px 10px -20px #c7c7c7;
  201. position: absolute;
  202. top: 0;
  203. left: 0;
  204. }
  205. .swiper {
  206. height: 100%;
  207. border-radius: 20rpx;
  208. }
  209. .swiperItem{
  210. border-radius: 20rpx;
  211. }
  212. .swiperImg {
  213. display: block;
  214. width: 100%;
  215. height: 100%;
  216. border-radius: 20rpx;
  217. }
  218. .contentBox {
  219. height: calc(100vh - 330rpx);
  220. margin-top: 320rpx;
  221. padding: 10rpx 20rpx 0;
  222. position: relative;
  223. z-index: 9;
  224. background-color: #fff;
  225. overflow-y: auto;
  226. }
  227. .operateBox{
  228. display: flex;
  229. justify-content: space-between;
  230. align-items: center;
  231. flex-flow: wrap;
  232. align-content: flex-start;
  233. }
  234. .operateItemBox{
  235. display: inline-block;
  236. width: calc(50% - 10rpx);
  237. padding-bottom: 20rpx;
  238. }
  239. .operateItem {
  240. display: inline-block;
  241. width: 100%;
  242. height: 100%;
  243. text-align: center;
  244. border-radius: 14rpx;
  245. position: relative;
  246. }
  247. .operateItemBGImg {
  248. width: 100%;
  249. height: 100%;
  250. }
  251. .operateItemText{
  252. position: absolute;
  253. bottom: 10%;
  254. left: 0rpx;
  255. width: calc(100% - 40rpx);
  256. padding: 0 20rpx;
  257. text-align: center;
  258. font-size: 22rpx;
  259. height: 64rpx;
  260. line-height: 32rpx;
  261. color: #777;
  262. white-space: pre-line;
  263. overflow: hidden;
  264. text-overflow: ellipsis;
  265. display: -webkit-box;
  266. -webkit-box-orient: vertical;
  267. -webkit-line-clamp: 2;
  268. }
  269. </style>