API.nvue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <template>
  2. <view class="uni-container">
  3. <template v-if="showSetTabBarPage">
  4. <set-tab-bar @unmount="leaveSetTabBarPage"></set-tab-bar>
  5. </template>
  6. <template v-else>
  7. <view v-if="!hasLeftWin" class="uni-header-logo">
  8. <image class="uni-header-image" src="/static/apiIndex.png"></image>
  9. </view>
  10. <view v-if="!hasLeftWin" class="uni-hello-text">
  11. <text class="hello-text">以下将演示uni-app接口能力,详细文档见:</text>
  12. <u-link class="hello-link" :href="'https://uniapp.dcloud.io/api/'" :text="'https://uniapp.dcloud.io/api/'"
  13. :inWhiteList="true"></u-link>
  14. </view>
  15. <view class="uni-panel" v-for="(item, index) in list" :key="item.id">
  16. <view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index, item.id)">
  17. <text class="uni-panel-text">{{item.name}}</text>
  18. <text class="uni-panel-icon uni-icon" :class="item.open ? 'uni-panel-icon-on' : ''">{{item.pages ? '&#xe581;' : '&#xe470;'}}</text>
  19. </view>
  20. <view class="uni-panel-c" v-if="item.open">
  21. <view :class="{'left-win-active': leftWinActive === item2.url && hasLeftWin, 'pc-hide': item2.name === '设置TabBar' && hasLeftWin}" class="uni-navigate-item" v-for="(item2,key) in item.pages" :key="key" :url="item.url" @click="goDetailPage(item.id, item2.url)">
  22. <text class="uni-navigate-text">{{item2.name ? item2.name : item2}}</text>
  23. <text class="uni-navigate-icon uni-icon">&#xe470;</text>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. </view>
  29. </template>
  30. <script>
  31. import setTabBar from '@/components/api-set-tabbar.nvue';
  32. export default {
  33. components: {
  34. setTabBar
  35. },
  36. props: {
  37. hasLeftWin: {
  38. type: Boolean
  39. },
  40. leftWinActive: {
  41. type: String
  42. }
  43. },
  44. data() {
  45. // 暂时这么写,后面看怎么优化。
  46. let mediaPages = [{
  47. name: '图片',
  48. url: 'image'
  49. },
  50. // #ifndef MP-LARK
  51. {
  52. name: '音频',
  53. url: 'inner-audio'
  54. },
  55. // #endif
  56. // #ifdef APP-PLUS || MP-WEIXIN || MP-BAIDU || MP-QQ|| MP-JD
  57. {
  58. name: '录音',
  59. url: 'voice'
  60. },
  61. {
  62. name: '背景音频',
  63. url: 'background-audio'
  64. },
  65. // #endif
  66. // #ifndef MP-ALIPAY
  67. {
  68. name: '视频',
  69. url: 'video'
  70. },
  71. // #endif
  72. // #ifndef H5
  73. {
  74. name: '文件',
  75. url: 'file'
  76. },
  77. // #endif
  78. // #ifndef H5 || MP-ALIPAY
  79. {
  80. name: '保存媒体到本地',
  81. url: 'save-media'
  82. }
  83. // #endif
  84. ];
  85. const list = [{
  86. id: 'page',
  87. name: '界面',
  88. open: false,
  89. pages: [{
  90. name: '设置导航条',
  91. url: 'set-navigation-bar-title'
  92. },
  93. //#ifdef APP-PLUS
  94. {
  95. name: '原生子窗体',
  96. url: 'subnvue'
  97. },
  98. //#endif
  99. {
  100. name: '页面跳转',
  101. url: 'navigator'
  102. },
  103. //#ifndef MP-TOUTIAO
  104. {
  105. name: '设置TabBar',
  106. url: 'set-tabbar'
  107. },
  108. //#endif
  109. {
  110. name: '下拉刷新',
  111. url: 'pull-down-refresh'
  112. },
  113. {
  114. name: '创建动画',
  115. url: 'animation'
  116. },
  117. // #ifndef QUICKAPP-WEBVIEW-UNION
  118. {
  119. name: '创建绘画',
  120. url: 'canvas'
  121. },
  122. // #endif
  123. // #ifndef MP-LARK
  124. {
  125. name: '节点信息',
  126. url: 'get-node-info'
  127. },
  128. // #endif
  129. {
  130. name: '节点布局交互状态',
  131. url: 'intersection-observer'
  132. },
  133. {
  134. name: '显示操作菜单',
  135. url: 'action-sheet'
  136. },
  137. {
  138. name: '显示模态弹窗',
  139. url: 'modal'
  140. },
  141. {
  142. name: '显示加载提示框',
  143. url: 'show-loading'
  144. },
  145. {
  146. name: '显示消息提示框',
  147. url: 'toast'
  148. }
  149. ]
  150. },
  151. {
  152. id: 'device',
  153. name: '设备',
  154. open: false,
  155. pages: [{
  156. name: '获取设备网络状态',
  157. url: 'get-network-type'
  158. },
  159. {
  160. name: '获取设备系统信息',
  161. url: 'get-system-info'
  162. },
  163. {
  164. name: '打电话',
  165. url: 'make-phone-call'
  166. },
  167. //#ifndef H5
  168. {
  169. name: '震动',
  170. url: 'vibrate'
  171. },
  172. {
  173. name: '添加手机联系人',
  174. url: 'add-phone-contact'
  175. },
  176. {
  177. name: '扫码',
  178. url: 'scan-code'
  179. },
  180. //#endif
  181. {
  182. name: '剪贴板',
  183. url: 'clipboard'
  184. },
  185. // #ifndef H5 || MP-ALIPAY
  186. {
  187. name: '屏幕亮度',
  188. url: 'brightness'
  189. },
  190. // #endif
  191. // #ifdef APP-PLUS || MP-WEIXIN || MP-QQ || MP-JD
  192. {
  193. name: '蓝牙',
  194. url: 'bluetooth'
  195. },
  196. // #endif
  197. // #ifdef APP-PLUS || MP-WEIXIN || MP-QQ
  198. {
  199. name: '生物认证',
  200. url: 'soter'
  201. },
  202. // #endif
  203. // #ifdef APP-PLUS || MP-WEIXIN
  204. {
  205. name: 'iBeacon',
  206. url: 'ibeacon'
  207. },
  208. // #endif
  209. // #ifdef APP || MP-WEIXIN
  210. {
  211. name: '监听加速度传感器',
  212. url: 'on-accelerometer-change'
  213. },
  214. // #endif
  215. // #ifdef APP || H5 ||MP-WEIXIN
  216. {
  217. name: '监听罗盘数据',
  218. url: 'on-compass-change'
  219. },
  220. // #endif
  221. //#ifdef APP-PLUS
  222. {
  223. name: '监听距离传感器',
  224. url: '/platforms/app-plus/proximity/proximity'
  225. },
  226. {
  227. name: '监听方向传感器',
  228. url: '/platforms/app-plus/orientation/orientation'
  229. }
  230. //#endif
  231. ]
  232. },
  233. {
  234. id: 'network',
  235. name: '网络',
  236. open: false,
  237. pages: [{
  238. name: '发起一个请求',
  239. url: 'request'
  240. },
  241. {
  242. name: '上传文件',
  243. url: 'upload-file'
  244. },
  245. {
  246. name: '下载文件',
  247. url: 'download-file'
  248. }
  249. ]
  250. },
  251. {
  252. id: 'websocket',
  253. name: 'websocket',
  254. open: false,
  255. pages: [
  256. // #ifndef MP-ALIPAY
  257. {
  258. name: 'socketTask',
  259. url: 'websocket-socketTask'
  260. },
  261. // #endif
  262. {
  263. name: '全局websocket',
  264. url: 'websocket-global'
  265. }
  266. ]
  267. },
  268. {
  269. id: 'media',
  270. name: '媒体',
  271. open: false,
  272. pages: mediaPages
  273. },
  274. // #ifndef MP-KUAISHOU
  275. {
  276. id: 'location',
  277. name: '位置',
  278. open: false,
  279. pages: [{
  280. name: '获取当前位置',
  281. url: 'get-location'
  282. },
  283. {
  284. name: '使用地图查看位置',
  285. url: 'open-location'
  286. },
  287. // #ifndef MP-TOUTIAO
  288. {
  289. name: '使用地图选择位置',
  290. url: 'choose-location'
  291. }
  292. // #endif
  293. // #ifndef MP-QQ || MP-TOUTIAO || MP-LARK
  294. ,
  295. {
  296. name: '地图控制',
  297. url: 'map'
  298. }
  299. // #endif
  300. // #ifdef APP-PLUS
  301. ,
  302. {
  303. name: '地图搜索',
  304. url: 'map-search'
  305. }
  306. // #endif
  307. ]
  308. },
  309. // #endif
  310. {
  311. id: 'storage',
  312. name: '数据',
  313. open: false,
  314. pages: [{
  315. name: '数据存储(key-value)',
  316. url: 'storage'
  317. },
  318. // #ifdef APP-PLUS
  319. {
  320. name: 'SQLite',
  321. url: 'sqlite'
  322. }
  323. // #endif
  324. ]
  325. },
  326. // #ifdef APP-PLUS || MP-WEIXIN
  327. {
  328. url: 'rewarded-video-ad',
  329. name: '激励视频广告',
  330. open: false
  331. },
  332. // #endif
  333. // #ifdef APP-PLUS
  334. {
  335. url: 'full-screen-video-ad',
  336. name: '全屏视频广告',
  337. open: false
  338. },
  339. // #endif
  340. // #ifndef H5 || QUICKAPP-WEBVIEW || MP-KUAISHOU || MP-LARK
  341. {
  342. id: 'login',
  343. name: '登录',
  344. open: false,
  345. pages: [{
  346. name: '登录',
  347. url: 'login'
  348. },
  349. {
  350. name: '获取用户信息',
  351. url: 'get-user-info'
  352. }
  353. ]
  354. },
  355. // #endif
  356. // #ifndef H5 || QUICKAPP-WEBVIEW-UNION
  357. {
  358. id: 'share',
  359. name: '分享',
  360. open: false,
  361. pages: [{
  362. name: '分享',
  363. url: 'share'
  364. }]
  365. },
  366. // #endif
  367. // #ifdef APP-PLUS || MP-WEIXIN
  368. {
  369. id: 'payment',
  370. name: '支付',
  371. open: false,
  372. pages: [{
  373. name: '发起支付',
  374. url: 'request-payment'
  375. }]
  376. },
  377. // #endif
  378. // #ifdef APP-PLUS
  379. {
  380. id: 'speech',
  381. name: '语音',
  382. open: false,
  383. pages: [{
  384. name: '语音识别',
  385. url: '/platforms/app-plus/speech/speech'
  386. }]
  387. },
  388. {
  389. id: 'push',
  390. name: '推送',
  391. open: false,
  392. pages: [{
  393. name: '推送',
  394. url: '/platforms/app-plus/push/push'
  395. }]
  396. }
  397. //#endif
  398. ];
  399. return {
  400. showSetTabBarPage: false,
  401. list: list,
  402. notForPc: [{
  403. name: '设置TabBar',
  404. url: 'set-tabbar'
  405. }]
  406. };
  407. },
  408. onShareAppMessage() {
  409. return {
  410. title: '欢迎体验uni-app',
  411. path: '/pages/tabBar/API/API'
  412. };
  413. },
  414. onNavigationBarButtonTap(e) {
  415. uni.navigateTo({
  416. url: '/pages/about/about'
  417. });
  418. },
  419. onLoad() {
  420. },
  421. onReady() {
  422. },
  423. onShow() {
  424. this.navigateFlag = false;
  425. this.leaveSetTabBarPage();
  426. },
  427. onHide() {
  428. this.leaveSetTabBarPage();
  429. },
  430. // #ifdef H5
  431. watch:{
  432. $route: {
  433. immediate: true,
  434. handler(newRoute) {
  435. if (newRoute.matched.length) {
  436. let path = newRoute.path.split('/')[3]
  437. for (const item of this.list) {
  438. if (Array.isArray(item.pages)) {
  439. for (const page of item.pages) {
  440. if (page === path || page.url && page.url === path) {
  441. item.open = true
  442. }
  443. }
  444. }
  445. }
  446. }
  447. }
  448. }
  449. },
  450. // #endif
  451. methods: {
  452. triggerCollapse(e, id) {
  453. if (!this.list[e].pages) {
  454. this.goDetailPage('', this.list[e].url);
  455. return;
  456. }
  457. for (var i = 0; i < this.list.length; ++i) {
  458. if (e === i) {
  459. this.list[i].open = !this.list[i].open;
  460. } else {
  461. this.list[i].open = false;
  462. }
  463. }
  464. },
  465. goDetailPage(panel, e) {
  466. if (e === 'set-tabbar') {
  467. this.showSetTabBarPage = true;
  468. return;
  469. }
  470. let url = ~e.indexOf('platform') ? e : '/pages/API/' + e + '/' + e;
  471. if (this.hasLeftWin) {
  472. uni.reLaunch({
  473. url: url
  474. })
  475. } else {
  476. uni.navigateTo({
  477. url: url
  478. })
  479. }
  480. },
  481. leaveSetTabBarPage() {
  482. this.showSetTabBarPage = false;
  483. }
  484. }
  485. };
  486. </script>
  487. <style>
  488. @import '../../../common/uni-nvue.css';
  489. </style>