open-location.uvue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-common-mt">
  5. <form @submit="openLocation">
  6. <view class="uni-list">
  7. <view class="uni-list-cell">
  8. <view class="uni-list-cell-left">
  9. <view class="uni-label">经度</view>
  10. </view>
  11. <view class="uni-list-cell-db">
  12. <input v-model.number="longitude" class="uni-input" type="text" :disabled="true" />
  13. </view>
  14. </view>
  15. <view class="uni-list-cell">
  16. <view class="uni-list-cell-left">
  17. <view class="uni-label">纬度</view>
  18. </view>
  19. <view class="uni-list-cell-db">
  20. <input v-model.number="latitude" class="uni-input" type="text" :disabled="true" />
  21. </view>
  22. </view>
  23. <view class="uni-list-cell">
  24. <view class="uni-list-cell-left">
  25. <view class="uni-label">位置名称</view>
  26. </view>
  27. <view class="uni-list-cell-db">
  28. <input v-model="name" class="uni-input" type="text" :disabled="true" />
  29. </view>
  30. </view>
  31. <view class="uni-list-cell">
  32. <view class="uni-list-cell-left">
  33. <view class="uni-label">详细位置</view>
  34. </view>
  35. <view class="uni-list-cell-db">
  36. <input v-model="address" class="uni-input" type="text" :disabled="true" />
  37. </view>
  38. </view>
  39. </view>
  40. <view class="uni-padding-wrap">
  41. <view class="tips">注意:需要正确配置地图服务商的Key才能正常显示位置</view>
  42. <view class="uni-btn-v uni-common-mt">
  43. <button type="primary" formType="submit">查看位置</button>
  44. </view>
  45. </view>
  46. </form>
  47. </view>
  48. </view>
  49. </template>
  50. <script lang="uts">
  51. import {
  52. state,
  53. setLifeCycleNum
  54. } from '@/store/index.uts'
  55. export default {
  56. data() {
  57. return {
  58. title: 'openLocation',
  59. longitude: 116.39747,
  60. latitude: 39.9085,
  61. name: '天安门',
  62. address: '北京市东城区东长安街',
  63. // 自动化测试
  64. dialogPagesNum: -1,
  65. }
  66. },
  67. onShow() {
  68. console.log("Page Show");
  69. // 自动化测试
  70. setLifeCycleNum(state.lifeCycleNum + 1)
  71. },
  72. onHide() {
  73. console.log("Page Hide");
  74. // 自动化测试
  75. setLifeCycleNum(state.lifeCycleNum - 1)
  76. },
  77. methods: {
  78. openLocation: function () {
  79. uni.openLocation({
  80. longitude: this.longitude,
  81. latitude: this.latitude,
  82. name: this.name,
  83. address: this.address
  84. })
  85. // 自动化测试
  86. setTimeout(() => {
  87. this.test()
  88. }, 500)
  89. },
  90. // 自动化测试
  91. test() {
  92. const pages = getCurrentPages()
  93. const page = pages[pages.length - 1]
  94. // #ifdef APP || WEB
  95. const dialogPages = page.getDialogPages()
  96. this.dialogPagesNum = dialogPages.length
  97. // #endif
  98. },
  99. // 自动化测试
  100. setLifeCycleNum(value : number) {
  101. setLifeCycleNum(value)
  102. },
  103. // 自动化测试
  104. getLifeCycleNum() : number {
  105. return state.lifeCycleNum
  106. },
  107. }
  108. }
  109. </script>
  110. <style>
  111. .uni-list-cell-left {
  112. padding: 0 15px;
  113. }
  114. .tips {
  115. font-size: 12px;
  116. margin-top: 15px;
  117. opacity: .8;
  118. }
  119. </style>