index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view class="main-Location">
  3. <!-- 字母区域 -->
  4. <view class="Location-Letter">
  5. <view hover-class="Click-Latter" @tap="getLetter('ScrollTop')">*</view>
  6. <view v-for="(l,i) in LatterName" :key="i" hover-class="Click-Latter" @tap="getLetter(l)"
  7. :style="{'color': LetterId === l ? '#ffbc00' : '#000' }">{{l}}</view>
  8. </view>
  9. <scroll-view scroll-y="true" class="ynq-ScrollView" :scroll-into-view="LetterId">
  10. <!-- 城市列表 -->
  11. <view class="ynq-CityList">
  12. <block v-for="(item,index) in CityList" :key="index">
  13. <view class="ynq-CityLetter" :id="item.initial">{{item.initial}}</view>
  14. <view class="ynq-CityLine">
  15. <text @tap="getStorage(item_city)" v-for="(item_city,name_index) in item.list"
  16. :key="name_index">{{item_city.name}}</text>
  17. </view>
  18. </block>
  19. </view>
  20. </scroll-view>
  21. </view>
  22. </template>
  23. <script setup lang="ts">
  24. import { getCurrentInstance, ref } from 'vue';
  25. //该依赖已内置不需要单独安装
  26. import { onLoad } from "@dcloudio/uni-app";
  27. // 请求接口
  28. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  29. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  30. // 基本信息
  31. const config = ref({ logoUrl: [] });
  32. const CityName = ref('');
  33. const LatterName = ref(['全', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']);
  34. const CityList = ref($config.china);
  35. const LetterId = ref('');
  36. onLoad(async () => {
  37. await searchConfig();
  38. await search();
  39. })
  40. // config信息
  41. const searchConfig = async () => {
  42. config.value = uni.getStorageSync('config');
  43. };
  44. // 查询
  45. const search = async () => {
  46. };
  47. // 获取定位点
  48. const getLetter = (name) => {
  49. LetterId.value = name
  50. // 跳转城市首字母定位
  51. uni.pageScrollTo({
  52. selector: '#' + name,
  53. duration: 300
  54. })
  55. };
  56. // 存储城市缓存(点击城市)
  57. const getStorage = (item) => {
  58. uni.$emit('toCity', item)
  59. // 4. 返回上一页面
  60. uni.navigateBack({
  61. delta: 1 // 返回的页面数
  62. })
  63. };
  64. </script>
  65. <style lang="scss" scoped>
  66. .main-Location {
  67. height: 100vh;
  68. }
  69. // 侧边字母选择栏
  70. .Location-Letter {
  71. position: fixed;
  72. right: 5px;
  73. top: 80px;
  74. width: 15px;
  75. z-index: 100;
  76. color: #c8c9cc;
  77. view {
  78. display: block;
  79. width: 15px;
  80. text-align: center;
  81. padding: 1px 0 0 0;
  82. font-size: var(--font12Size);
  83. transition: ease .3s;
  84. -webkit-transition: ease .3s;
  85. }
  86. }
  87. // 城市列表
  88. .ynq-CityList {
  89. padding: 10px 0;
  90. .ynq-CityLetter {
  91. font-size: var(--font16Size);
  92. border-bottom: 1px solid #f7f7f7;
  93. padding: 5px;
  94. background-color: #f4f4f5;
  95. border-bottom: 0.5px solid #dadbde;
  96. }
  97. .ynq-CityLine {
  98. background-color: #fff;
  99. margin: 10px 0;
  100. text {
  101. display: block;
  102. line-height: 30px;
  103. padding: 10px 15px;
  104. font-size: var(--font14Size);
  105. border-bottom: 1px solid var(--f4Color);
  106. }
  107. }
  108. }
  109. </style>