Home.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 || '/pagesCare/Write/ReportHiddenDanger'
  111. // let strUrl = '/pagesCare/Write/ReportHiddenDanger'
  112. // let strUrl = '/pagesCare/Write/LivelihoodFacts'
  113. // let strUrl = '/pagesCare/Write/WeldingOperations'
  114. // let strUrl = 'navigateToMiniProgramByAppId?appId=wxc564149bc4d892f3&path=pages/index/index&type=WeldingOperations'
  115. // let strUrl = 'navigateToExternalLinks?externalUrl=https://zgyjglyzpt.cn'
  116. if (strUrl.indexOf("navigateToMiniProgramByAppId") !== -1){
  117. if(!strUrl || strUrl.split('?').length != 2 || strUrl.split('?')[1].split('&').length != 3){
  118. that.$util.msg('跳转地址配置错误!');
  119. }else {
  120. let appId = strUrl.split('?')[1].split('&')[0].split('=')[1] || '';
  121. let path = strUrl.split('?')[1].split('&')[1].split('=')[1] || '';
  122. let type = strUrl.split('?')[1].split('&')[2].split('=')[1] || '';
  123. if (type == 'WeldingOperations'){
  124. if (!that.openID) {
  125. that.$util.msg("请先登录", function(){
  126. uni.switchTab({
  127. url: "/pages/Index/Mine"
  128. })
  129. });
  130. return;
  131. }
  132. // path += '?openId=' + that.openID;
  133. uni.navigateToMiniProgram({
  134. appId: appId,
  135. path: path,
  136. extraData: {
  137. 'openId': that.openID
  138. },
  139. envVersion: 'release',
  140. fail(err) {
  141. that.$util.msg('您已取消打开');
  142. }
  143. })
  144. }else if (type == 'HomeworkReporte'){
  145. uni.navigateToMiniProgram({
  146. appId: appId,
  147. path: path,
  148. envVersion: 'release',
  149. fail(err) {
  150. that.$util.msg('您已取消打开');
  151. }
  152. })
  153. }
  154. }
  155. }else if (strUrl.indexOf("navigateToExternalLinks") !== -1){
  156. let externalUrl = strUrl.split('?')[1].split('=')[1];
  157. // that.getAuthorizeInfo(function(){
  158. uni.navigateTo({
  159. url: '/pages/ExternalLinks/Index?externalUrl=' + encodeURIComponent(externalUrl)
  160. })
  161. // });
  162. }else {
  163. if (!that.openID) {
  164. that.$util.msg("请先登录", function(){
  165. uni.switchTab({
  166. url: "/pages/Index/Mine"
  167. })
  168. });
  169. return;
  170. }
  171. uni.navigateTo({
  172. url: strUrl + '?id=' + encodeURIComponent(obj.id)
  173. });
  174. }
  175. },
  176. }
  177. }
  178. </script>
  179. <style lang="less">
  180. .container {
  181. background-color: #fff;
  182. }
  183. .contentBox {
  184. height: calc(100vh - 20rpx);
  185. padding: 20rpx 20rpx 0;
  186. position: relative;
  187. z-index: 9;
  188. background-color: #fff;
  189. overflow-y: auto;
  190. }
  191. .operateBox{
  192. display: flex;
  193. justify-content: space-between;
  194. align-items: center;
  195. flex-flow: wrap;
  196. align-content: flex-start;
  197. }
  198. .operateItemBox{
  199. display: inline-block;
  200. width: calc(50% - 10rpx);
  201. padding-bottom: 20rpx;
  202. }
  203. .operateItem {
  204. display: inline-block;
  205. width: 100%;
  206. height: 100%;
  207. text-align: center;
  208. border-radius: 14rpx;
  209. position: relative;
  210. }
  211. .operateItemBGImg {
  212. width: 100%;
  213. height: 100%;
  214. }
  215. .operateItemText{
  216. position: absolute;
  217. bottom: 10%;
  218. left: 0rpx;
  219. width: calc(100% - 40rpx);
  220. padding: 0 20rpx;
  221. text-align: center;
  222. font-size: 32rpx;
  223. line-height: 42rpx;
  224. color: #000;
  225. white-space: pre-line;
  226. overflow: hidden;
  227. text-overflow: ellipsis;
  228. display: -webkit-box;
  229. -webkit-box-orient: vertical;
  230. -webkit-line-clamp: 3;
  231. }
  232. </style>