Home.vue 6.1 KB

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