API.nvue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. //#ifndef H5 || MP-JD
  182. {
  183. name: '剪贴板',
  184. url: 'clipboard'
  185. },
  186. //#endif
  187. // #ifndef H5 || MP-ALIPAY
  188. {
  189. name: '屏幕亮度',
  190. url: 'brightness'
  191. },
  192. // #endif
  193. // #ifdef APP-PLUS || MP-WEIXIN || MP-QQ || MP-JD
  194. {
  195. name: '蓝牙',
  196. url: 'bluetooth'
  197. },
  198. // #endif
  199. // #ifdef APP-PLUS || MP-WEIXIN || MP-QQ
  200. {
  201. name: '生物认证',
  202. url: 'soter'
  203. },
  204. // #endif
  205. // #ifdef APP-PLUS || MP-WEIXIN
  206. {
  207. name: 'iBeacon',
  208. url: 'ibeacon'
  209. },
  210. // #endif
  211. // #ifndef H5
  212. {
  213. name: '监听加速度传感器',
  214. url: 'on-accelerometer-change'
  215. },
  216. // #endif
  217. // #ifndef H5 || MP-JD
  218. {
  219. name: '监听罗盘数据',
  220. url: 'on-compass-change'
  221. },
  222. // #endif
  223. //#ifdef APP-PLUS
  224. {
  225. name: '监听距离传感器',
  226. url: '/platforms/app-plus/proximity/proximity'
  227. },
  228. {
  229. name: '监听方向传感器',
  230. url: '/platforms/app-plus/orientation/orientation'
  231. }
  232. //#endif
  233. ]
  234. },
  235. {
  236. id: 'network',
  237. name: '网络',
  238. open: false,
  239. pages: [{
  240. name: '发起一个请求',
  241. url: 'request'
  242. },
  243. {
  244. name: '上传文件',
  245. url: 'upload-file'
  246. },
  247. {
  248. name: '下载文件',
  249. url: 'download-file'
  250. }
  251. ]
  252. },
  253. {
  254. id: 'websocket',
  255. name: 'websocket',
  256. open: false,
  257. pages: [
  258. // #ifndef MP-ALIPAY
  259. {
  260. name: 'socketTask',
  261. url: 'websocket-socketTask'
  262. },
  263. // #endif
  264. {
  265. name: '全局websocket',
  266. url: 'websocket-global'
  267. }
  268. ]
  269. },
  270. {
  271. id: 'media',
  272. name: '媒体',
  273. open: false,
  274. pages: mediaPages
  275. },
  276. // #ifndef MP-KUAISHOU
  277. {
  278. id: 'location',
  279. name: '位置',
  280. open: false,
  281. pages: [{
  282. name: '获取当前位置',
  283. url: 'get-location'
  284. },
  285. {
  286. name: '使用地图查看位置',
  287. url: 'open-location'
  288. },
  289. // #ifndef MP-TOUTIAO
  290. {
  291. name: '使用地图选择位置',
  292. url: 'choose-location'
  293. }
  294. // #endif
  295. // #ifndef MP-QQ || MP-TOUTIAO || MP-LARK
  296. ,
  297. {
  298. name: '地图控制',
  299. url: 'map'
  300. }
  301. // #endif
  302. // #ifdef APP-PLUS
  303. ,
  304. {
  305. name: '地图搜索',
  306. url: 'map-search'
  307. }
  308. // #endif
  309. ]
  310. },
  311. // #endif
  312. {
  313. id: 'storage',
  314. name: '数据',
  315. open: false,
  316. pages: [{
  317. name: '数据存储(key-value)',
  318. url: 'storage'
  319. },
  320. // #ifdef APP-PLUS
  321. {
  322. name: 'SQLite',
  323. url: 'sqlite'
  324. }
  325. // #endif
  326. ]
  327. },
  328. // #ifdef APP-PLUS || MP-WEIXIN
  329. {
  330. url: 'rewarded-video-ad',
  331. name: '激励视频广告',
  332. open: false
  333. },
  334. // #endif
  335. // #ifdef APP-PLUS
  336. {
  337. url: 'full-screen-video-ad',
  338. name: '全屏视频广告',
  339. open: false
  340. },
  341. // #endif
  342. // #ifndef H5 || QUICKAPP-WEBVIEW || MP-KUAISHOU || MP-LARK
  343. {
  344. id: 'login',
  345. name: '登录',
  346. open: false,
  347. pages: [{
  348. name: '登录',
  349. url: 'login'
  350. },
  351. {
  352. name: '获取用户信息',
  353. url: 'get-user-info'
  354. }
  355. ]
  356. },
  357. // #endif
  358. // #ifndef H5 || QUICKAPP-WEBVIEW-UNION
  359. {
  360. id: 'share',
  361. name: '分享',
  362. open: false,
  363. pages: [{
  364. name: '分享',
  365. url: 'share'
  366. }]
  367. },
  368. // #endif
  369. // #ifdef APP-PLUS || MP-WEIXIN
  370. {
  371. id: 'payment',
  372. name: '支付',
  373. open: false,
  374. pages: [{
  375. name: '发起支付',
  376. url: 'request-payment'
  377. }]
  378. },
  379. // #endif
  380. // #ifdef APP-PLUS
  381. {
  382. id: 'speech',
  383. name: '语音',
  384. open: false,
  385. pages: [{
  386. name: '语音识别',
  387. url: '/platforms/app-plus/speech/speech'
  388. }]
  389. },
  390. {
  391. id: 'push',
  392. name: '推送',
  393. open: false,
  394. pages: [{
  395. name: '推送',
  396. url: '/platforms/app-plus/push/push'
  397. }]
  398. }
  399. //#endif
  400. ];
  401. return {
  402. showSetTabBarPage: false,
  403. list: list,
  404. notForPc: [{
  405. name: '设置TabBar',
  406. url: 'set-tabbar'
  407. }]
  408. };
  409. },
  410. onShareAppMessage() {
  411. return {
  412. title: '欢迎体验uni-app',
  413. path: '/pages/tabBar/API/API'
  414. };
  415. },
  416. onNavigationBarButtonTap(e) {
  417. uni.navigateTo({
  418. url: '/pages/about/about'
  419. });
  420. },
  421. onLoad() {
  422. },
  423. onReady() {
  424. },
  425. onShow() {
  426. this.navigateFlag = false;
  427. this.leaveSetTabBarPage();
  428. },
  429. onHide() {
  430. this.leaveSetTabBarPage();
  431. },
  432. // #ifdef H5
  433. watch:{
  434. $route: {
  435. immediate: true,
  436. handler(newRoute) {
  437. if (newRoute.matched.length) {
  438. let path = newRoute.path.split('/')[3]
  439. for (const item of this.list) {
  440. if (Array.isArray(item.pages)) {
  441. for (const page of item.pages) {
  442. if (page === path || page.url && page.url === path) {
  443. item.open = true
  444. }
  445. }
  446. }
  447. }
  448. }
  449. }
  450. }
  451. },
  452. // #endif
  453. methods: {
  454. triggerCollapse(e, id) {
  455. if (!this.list[e].pages) {
  456. this.goDetailPage('', this.list[e].url);
  457. return;
  458. }
  459. for (var i = 0; i < this.list.length; ++i) {
  460. if (e === i) {
  461. this.list[i].open = !this.list[i].open;
  462. } else {
  463. this.list[i].open = false;
  464. }
  465. }
  466. },
  467. goDetailPage(panel, e) {
  468. if (e === 'set-tabbar') {
  469. this.showSetTabBarPage = true;
  470. return;
  471. }
  472. let url = ~e.indexOf('platform') ? e : '/pages/API/' + e + '/' + e;
  473. if (this.hasLeftWin) {
  474. uni.reLaunch({
  475. url: url
  476. })
  477. } else {
  478. uni.navigateTo({
  479. url: url
  480. })
  481. }
  482. },
  483. leaveSetTabBarPage() {
  484. this.showSetTabBarPage = false;
  485. }
  486. }
  487. };
  488. </script>
  489. <style>
  490. @import '../../../common/uni-nvue.css';
  491. </style>