views.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div class="wrapper">
  3. <!-- uni 中不能使用 vue component 所以用if判断每个组件 -->
  4. <div v-for="(item,index) in pageData.list" :key="index">
  5. <!-- 搜索栏,如果在楼层装修顶部则会自动浮动,否则不浮动 -->
  6. <u-navbar class="navbar" v-if="item.type == 'search'" :is-back="false" :is-fixed="index ===1 ? false : true">
  7. <search style="width:100%" :res="item.options" />
  8. <!-- #ifndef H5 -->
  9. <!-- 扫码功能 不兼容h5 详情文档: https://uniapp.dcloud.io/api/system/barcode?id=scancode -->
  10. <div slot="right" class="navbar-right">
  11. <u-icon name="scan" @click="scan()" color="#666" size="50"></u-icon>
  12. </div>
  13. <!-- #endif -->
  14. </u-navbar>
  15. <carousel v-if="item.type == 'carousel'" :res="item.options" />
  16. <titleLayout v-if="item.type == 'title'" :res="item.options" />
  17. <leftOneRightTwo v-if="item.type == 'leftOneRightTwo'" :res="item.options" />
  18. <leftTwoRightOne v-if="item.type == 'leftTwoRightOne'" :res="item.options" />
  19. <topOneBottomTwo v-if="item.type == 'topOneBottomTwo'" :res="item.options" />
  20. <topTwoBottomOne v-if="item.type == 'topTwoBottomOne'" :res="item.options" />
  21. <flexThree v-if="item.type == 'flexThree'" :res="item.options" />
  22. <flexFive v-if="item.type == 'flexFive'" :res="item.options" />
  23. <flexFour v-if="item.type == 'flexFour'" :res="item.options" />
  24. <flexTwo v-if="item.type == 'flexTwo'" :res="item.options" />
  25. <textPicture v-if="item.type == 'textPicture'" :res="item.options" />
  26. <menuLayout v-if="item.type == 'menu'" :res="item.options" />
  27. <flexOne v-if="item.type == 'flexOne'" :res="item.options" />
  28. <goods v-if="item.type == 'goods'" :res="item.options" />
  29. <group v-if="item.type == 'group'" :res="item.options" />
  30. <!-- <joinGroup v-if="item.type == 'joinGroup'" :res="item.options" /> -->
  31. <!-- <integral v-if="item.type == 'integral'" :res="item.options" /> -->
  32. <!-- <spike v-if="item.type == 'spike'" :res="item.options" /> -->
  33. </div>
  34. <u-no-network></u-no-network>
  35. </div>
  36. </template>
  37. <script>
  38. // 引用组件
  39. import tpl_banner from "@/pages/tabbar/home/template/tpl_banner"; //导航栏模块
  40. import tpl_title from "@/pages/tabbar/home/template/tpl_title"; //标题栏模块
  41. import tpl_left_one_right_two from "@/pages/tabbar/home/template/tpl_left_one_right_two"; //左一右二模块
  42. import tpl_left_two_right_one from "@/pages/tabbar/home/template/tpl_left_two_right_one"; //左二右一模块
  43. import tpl_top_one_bottom_two from "@/pages/tabbar/home/template/tpl_top_one_bottom_two"; //上一下二模块
  44. import tpl_top_two_bottom_one from "@/pages/tabbar/home/template/tpl_top_two_bottom_one"; //上二下一模块
  45. import tpl_flex_one from "@/pages/tabbar/home/template/tpl_flex_one"; //单行图片模块
  46. import tpl_flex_two from "@/pages/tabbar/home/template/tpl_flex_two"; //两张横图模块
  47. import tpl_flex_three from "@/pages/tabbar/home/template/tpl_flex_three"; //三列单行图片模块
  48. import tpl_flex_five from "@/pages/tabbar/home/template/tpl_flex_five"; //五列单行图片模块
  49. import tpl_flex_four from "@/pages/tabbar/home/template/tpl_flex_four"; //四列单行图片模块
  50. import tpl_text_picture from "@/pages/tabbar/home/template/tpl_text_picture"; //文字图片模板
  51. import tpl_menu from "@/pages/tabbar/home/template/tpl_menu"; //五列菜单模块
  52. import tpl_search from "@/pages/tabbar/home/template/tpl_search"; //搜索栏
  53. import tpl_group from "@/pages/tabbar/home/template/tpl_group"; //
  54. import tpl_goods from "@/pages/tabbar/home/template/tpl_goods"; //商品分类以及分类中的商品
  55. // 结束引用组件
  56. import { getFloorData } from "@/api/home"; //获取楼层装修接口
  57. import permision from "@/js_sdk/wa-permission/permission.js"; //权限工具类
  58. import config from "@/config/config";
  59. // TODO 后续开发
  60. // import tpl_join_group from "@/pages/tabbar/home/template/tpl_join_group";
  61. // import tpl_integral from "@/pages/tabbar/home/template/tpl_integral";
  62. // import tpl_spike from "@/pages/tabbar/home/template/tpl_spike";
  63. export default {
  64. data() {
  65. return {
  66. config,
  67. pageData: "", //楼层页面数据
  68. isIos: "",
  69. };
  70. },
  71. components: {
  72. carousel: tpl_banner,
  73. titleLayout: tpl_title,
  74. leftOneRightTwo: tpl_left_one_right_two,
  75. leftTwoRightOne: tpl_left_two_right_one,
  76. topOneBottomTwo: tpl_top_one_bottom_two,
  77. topTwoBottomOne: tpl_top_two_bottom_one,
  78. flexThree: tpl_flex_three,
  79. flexFive: tpl_flex_five,
  80. flexFour: tpl_flex_four,
  81. flexTwo: tpl_flex_two,
  82. textPicture: tpl_text_picture,
  83. menuLayout: tpl_menu,
  84. search: tpl_search,
  85. flexOne: tpl_flex_one,
  86. goods: tpl_goods,
  87. group: tpl_group,
  88. // spike: tpl_spike,
  89. // joinGroup: tpl_join_group,
  90. // integral: tpl_integral,
  91. },
  92. mounted() {
  93. this.init();
  94. // #ifdef MP-WEIXIN
  95. // 小程序默认分享
  96. uni.showShareMenu({ withShareTicket: true });
  97. // #endif
  98. },
  99. methods: {
  100. /**
  101. * 实例化首页数据楼层
  102. */
  103. init() {
  104. getFloorData().then((res) => {
  105. if (res.data.success) {
  106. this.pageData = JSON.parse(res.data.result.pageData);
  107. }
  108. });
  109. },
  110. /**
  111. * TODO 扫码功能后续还会后续增加
  112. * 应该实现的功能目前计划有:
  113. * 扫描商品跳转商品页面
  114. * 扫描活动跳转活动页面
  115. * 扫描二维码登录
  116. * 扫描其他站信息 弹出提示,返回首页。
  117. */
  118. seacnCode() {
  119. uni.scanCode({
  120. success: function (res) {
  121. let path = encodeURIComponent(res.result);
  122. config.scanAuthNavigation.forEach((src) => {
  123. if (res.result.indexOf(src) != -1) {
  124. uni.navigateTo({
  125. url: `/${res.result.substring(src.length)}`,
  126. });
  127. } else {
  128. setTimeout(() => {
  129. uni.navigateTo({
  130. url: "/pages/tabbar/home/web-view?src=" + path,
  131. });
  132. }, 100);
  133. }
  134. });
  135. },
  136. });
  137. },
  138. /**
  139. * 提示获取权限
  140. */
  141. tipsGetSettings() {
  142. uni.showModal({
  143. title: "提示",
  144. content: "您已经关闭相机权限,去设置",
  145. success: function (res) {
  146. if (res.confirm) {
  147. if (this.isIos) {
  148. plus.runtime.openURL("app-settings:");
  149. } else {
  150. permision.gotoAppPermissionSetting();
  151. }
  152. }
  153. },
  154. });
  155. },
  156. /**
  157. * 唤醒客户端扫码
  158. * 没权限去申请权限,有权限获取扫码功能
  159. */
  160. async scan() {
  161. // #ifdef APP-PLUS
  162. this.isIos = plus.os.name == "iOS";
  163. // 判断是否是Ios
  164. if (this.isIos) {
  165. const iosFirstCamera = uni.getStorageSync("iosFirstCamera"); //是不是第一次开启相机
  166. if (iosFirstCamera !== "false") {
  167. uni.setStorageSync("iosFirstCamera", "false"); //设为false就代表不是第一次开启相机
  168. this.seacnCode();
  169. } else {
  170. if (permision.judgeIosPermission("camera")) {
  171. this.seacnCode();
  172. } else {
  173. // 没有权限提醒是否去申请权限
  174. this.tipsGetSettings();
  175. }
  176. }
  177. } else {
  178. /**
  179. * TODO 安卓 权限已经授权了,调用api总是显示用户已永久拒绝申请。人傻了
  180. * TODO 如果xdm有更好的办法请在 https://gitee.com/beijing_hongye_huicheng/lilishop/issues 提下谢谢
  181. */
  182. this.seacnCode();
  183. }
  184. // #endif
  185. // #ifdef MP-WEIXIN
  186. this.seacnCode();
  187. // #endif
  188. },
  189. },
  190. };
  191. </script>
  192. <style scoped lang="scss">
  193. .navbar-right {
  194. padding: 0 16rpx 0 0;
  195. }
  196. </style>