component.nvue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="uni-container">
  3. <view v-if="!hasLeftWin" class="uni-header-logo">
  4. <image class="uni-header-image" src="/static/componentIndex.png"></image>
  5. </view>
  6. <view v-if="!hasLeftWin" class="uni-hello-text">
  7. <text class="hello-text">uni-app内置组件,展示样式仅供参考,文档详见:</text>
  8. <u-link class="hello-link" :href="'https://uniapp.dcloud.io/component/'" :text="'https://uniapp.dcloud.io/component/'"
  9. :inWhiteList="true"></u-link>
  10. </view>
  11. <view class="uni-panel" v-for="(item, index) in list" :key="item.id">
  12. <view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index, item.id)">
  13. <text class="uni-panel-text">{{item.name}}</text>
  14. <text class="uni-panel-icon uni-icon" :class="item.open ? 'uni-panel-icon-on' : ''">{{item.pages ? '&#xe581;' : '&#xe470;'}}</text>
  15. </view>
  16. <view class="uni-panel-c" v-if="item.open">
  17. <view :class="{'left-win-active': leftWinActive === (item2.url ? item2.url.split('/')[3] : item2) && hasLeftWin}"
  18. class="uni-navigate-item" v-for="(item2,key) in item.pages" :key="key" @click="goDetailPage(item.id, item2)">
  19. <text class="uni-navigate-text">{{item2.name ? item2.name : item2}}</text>
  20. <text class="uni-navigate-icon uni-icon">&#xe470;</text>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. // TODO 修复Android v3 加载过慢问题
  28. // #ifdef APP-PLUS
  29. var domModule = weex.requireModule('dom');
  30. domModule.addRule('fontFace', {
  31. 'fontFamily': "uniicons",
  32. 'src': "url('/static/uni.ttf')"
  33. });
  34. // #endif
  35. export default {
  36. props: {
  37. hasLeftWin: {
  38. type: Boolean
  39. },
  40. leftWinActive: {
  41. type: String
  42. }
  43. },
  44. data() {
  45. return {
  46. list: [{
  47. id: 'view',
  48. name: '视图容器',
  49. open: false,
  50. pages: [
  51. 'view',
  52. 'scroll-view',
  53. 'swiper'
  54. // #ifndef MP-TOUTIAO || MP-LARK
  55. ,
  56. 'movable-view',
  57. 'cover-view'
  58. // #endif
  59. ]
  60. }, {
  61. id: 'content',
  62. name: '基础内容',
  63. open: false,
  64. pages: ['text', 'rich-text', 'progress']
  65. }, {
  66. id: 'form',
  67. name: '表单组件',
  68. open: false,
  69. pages: ['button', 'checkbox', 'form', 'input', 'label', 'picker', 'picker-view', 'radio',
  70. 'slider',
  71. 'switch', 'textarea',
  72. // #ifdef APP-PLUS || MP-WEIXIN || H5
  73. 'editor',
  74. // #endif
  75. ]
  76. }, {
  77. id: 'nav',
  78. name: '导航',
  79. open: false,
  80. pages: ['navigator']
  81. }, {
  82. id: 'media',
  83. name: '媒体组件',
  84. open: false,
  85. pages: [
  86. 'image',
  87. 'video'
  88. ],
  89. },
  90. // #ifndef MP-TOUTIAO || MP-KUAISHOU
  91. {
  92. id: 'map',
  93. name: '地图',
  94. open: false,
  95. pages: ['map']
  96. },
  97. // #endif
  98. // #ifndef QUICKAPP-WEBVIEW-UNION
  99. {
  100. id: 'canvas',
  101. name: '画布',
  102. open: false,
  103. pages: ['canvas']
  104. },
  105. // #endif
  106. // #ifdef APP-PLUS || H5
  107. {
  108. id: 'web-view',
  109. name: '网页',
  110. open: false,
  111. pages: [{
  112. name: '网络网页',
  113. url: '/pages/component/web-view/web-view'
  114. }, {
  115. name: '本地网页',
  116. url: '/pages/component/web-view-local/web-view-local'
  117. }]
  118. },
  119. // #endif
  120. // #ifndef APP-PLUS || H5 || MP-LARK || MP-JD
  121. {
  122. id: 'web-view',
  123. name: '网页',
  124. open: false,
  125. pages: ['web-view']
  126. },
  127. // #endif
  128. // #ifndef H5 || MP-BAIDU || QUICKAPP-WEBVIEW || MP-LARK || MP-JD
  129. {
  130. id: 'ad',
  131. url: 'ad',
  132. name: 'AD组件',
  133. open: false
  134. },
  135. // #endif
  136. ]
  137. }
  138. },
  139. onShareAppMessage() {
  140. return {
  141. title: '欢迎体验uni-app',
  142. path: '/pages/tabBar/component/component'
  143. }
  144. },
  145. onNavigationBarButtonTap(e) {
  146. uni.navigateTo({
  147. url: '/pages/about/about'
  148. });
  149. },
  150. // #ifdef H5
  151. watch: {
  152. $route: {
  153. immediate: true,
  154. handler(newRoute) {
  155. if (newRoute.matched.length) {
  156. let path = newRoute.path.split('/')[3]
  157. for (const item of this.list) {
  158. if (Array.isArray(item.pages)) {
  159. for (const page of item.pages) {
  160. if (page === path || page.url && page.url === newRoute.path) {
  161. item.open = true
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }
  168. }
  169. },
  170. // #endif
  171. methods: {
  172. triggerCollapse(e, id) {
  173. if (!this.list[e].pages) {
  174. this.goDetailPage('', this.list[e].url);
  175. return;
  176. }
  177. for (var i = 0; i < this.list.length; ++i) {
  178. if (e === i) {
  179. this.list[i].open = !this.list[i].open;
  180. } else {
  181. this.list[i].open = false;
  182. }
  183. }
  184. },
  185. goDetailPage(panel, e) {
  186. if (typeof e === 'string') {
  187. const url = '/pages/component/' + e + '/' + e
  188. if (this.hasLeftWin) {
  189. uni.reLaunch({
  190. url: url
  191. })
  192. } else {
  193. uni.navigateTo({
  194. url: url
  195. })
  196. }
  197. } else {
  198. if (this.hasLeftWin) {
  199. uni.reLaunch({
  200. url: e.url
  201. })
  202. } else {
  203. uni.navigateTo({
  204. url: e.url
  205. })
  206. }
  207. }
  208. }
  209. }
  210. }
  211. </script>
  212. <style>
  213. @import '../../../common/uni-nvue.css';
  214. </style>