views.vue 7.9 KB

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