views.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. // TODO 后续开发
  59. // import tpl_join_group from "@/pages/tabbar/home/template/tpl_join_group";
  60. // import tpl_integral from "@/pages/tabbar/home/template/tpl_integral";
  61. // import tpl_spike from "@/pages/tabbar/home/template/tpl_spike";
  62. export default {
  63. data() {
  64. return {
  65. pageData: "", //楼层页面数据
  66. };
  67. },
  68. components: {
  69. carousel: tpl_banner,
  70. titleLayout: tpl_title,
  71. leftOneRightTwo: tpl_left_one_right_two,
  72. leftTwoRightOne: tpl_left_two_right_one,
  73. topOneBottomTwo: tpl_top_one_bottom_two,
  74. topTwoBottomOne: tpl_top_two_bottom_one,
  75. flexThree: tpl_flex_three,
  76. flexFive: tpl_flex_five,
  77. flexFour: tpl_flex_four,
  78. flexTwo: tpl_flex_two,
  79. textPicture: tpl_text_picture,
  80. menuLayout: tpl_menu,
  81. search: tpl_search,
  82. flexOne: tpl_flex_one,
  83. goods: tpl_goods,
  84. group: tpl_group,
  85. // spike: tpl_spike,
  86. // joinGroup: tpl_join_group,
  87. // integral: tpl_integral,
  88. },
  89. mounted() {
  90. this.init();
  91. },
  92. methods: {
  93. /**
  94. * 实例化首页数据楼层
  95. */
  96. init() {
  97. getFloorData().then((res) => {
  98. if (res.data.success) {
  99. this.pageData = JSON.parse(res.data.result.pageData);
  100. }
  101. });
  102. },
  103. /**
  104. * TODO 扫码功能后续还会后续增加
  105. * 应该实现的功能目前计划有:
  106. * 扫描商品跳转商品页面
  107. * 扫描活动跳转活动页面
  108. * 扫描二维码登录
  109. * 扫描其他站信息 弹出提示,返回首页。
  110. */
  111. seacnCode() {
  112. uni.scanCode({
  113. success: function (res) {
  114. let path = encodeURIComponent(res.result);
  115. // 扫码成功后跳转到webview页面
  116. setTimeout(() => {
  117. uni.navigateTo({
  118. url: "/pages/tabbar/home/web-view?src=" + path,
  119. });
  120. }, 100);
  121. },
  122. });
  123. },
  124. /**
  125. * 提示获取权限
  126. */
  127. tipsGetSettings() {
  128. uni.showModal({
  129. title: "提示",
  130. content: "您已经关闭相机权限,去设置",
  131. success: function (res) {
  132. if (res.confirm) {
  133. let isIos = plus.os.name == "iOS";
  134. if (isIos) {
  135. plus.runtime.openURL("app-settings:");
  136. } else {
  137. permision.gotoAppPermissionSetting()
  138. }
  139. }
  140. },
  141. });
  142. },
  143. /**
  144. * 唤醒客户端扫码
  145. * 没权限去申请权限,有权限获取扫码功能
  146. */
  147. async scan() {
  148. // #ifdef APP-PLUS
  149. let isIos = plus.os.name == "iOS";
  150. // 判断是否是Ios
  151. if (isIos) {
  152. if (permision.judgeIosPermission("camera")) {
  153. this.seacnCode();
  154. } else {
  155. // 没有权限提醒是否去申请权限
  156. uni.showModal({
  157. title: "提示",
  158. content: "您已经关闭相机权限,去设置",
  159. success: function (res) {
  160. if (res.confirm) {
  161. plus.runtime.openURL("app-settings:");
  162. }
  163. },
  164. });
  165. }
  166. } else {
  167. // 安卓
  168. const result = await permision.requestAndroidPermission("CAMERA");
  169. if (result == 1 || result == 0) {
  170. this.seacnCode();
  171. } else {
  172. this.tipsGetSettings();
  173. }
  174. }
  175. // #endif
  176. // #ifdef MP-WEIXIN
  177. this.seacnCode();
  178. // #endif
  179. },
  180. },
  181. };
  182. </script>
  183. <style scoped lang="scss">
  184. .navbar-right {
  185. padding: 0 16rpx 0 0;
  186. }
  187. </style>