Просмотр исходного кода

feat:更新城市列表代码

jinx 4 лет назад
Родитель
Сommit
60bc847887

+ 5 - 3
apps/RealtorEasier/app.js

@@ -2,7 +2,8 @@
 import {
   loadToken,
   loadUserInfo,
-  loadUserCode
+  loadUserCode,
+  loadHistoryCity
 } from './utils/storage'
 
 import ImApi from './apis/im'
@@ -163,7 +164,7 @@ getContact(isNewMsg) {
     token: loadToken(),
     raw_city: true,
     // city: '定位中...', // 默认进入首页的地址
-    city: '安克雷奇', // 默认进入首页的地址
+    city: '珠海', // 默认进入首页的地址
     province: '广东省',
     district: '',
     userinfo: loadUserInfo() || {},
@@ -172,6 +173,7 @@ getContact(isNewMsg) {
     messageList: [],
     unViewMsg: 0,
     conversations: [],
-    type: 'user'
+    type: 'user',
+    historyCity:loadHistoryCity() ||[],
   }
 });

+ 47 - 10
apps/RealtorEasier/pages/city/city.js

@@ -5,6 +5,11 @@ import {
 import states from './json/states'
 import cities from './json/cities'
 var wxaSortPicker = require('../../utils/wxaSortPicker/wxaSortPicker.js');
+import {
+  saveHistoryCity,
+  loadHistoryCity,
+  removeHistoryCity
+} from "../../utils/storage";
 const app = getApp();
 const CHINA = {}
 let _animation; // 动画实体
@@ -28,12 +33,18 @@ Page({
     apl_posArr: [],
     apl_index: 0,
     b_top: 0,
+    sliderHeight:0,
+    historyCity: [],
+    clientHeight:0
   },
 
   onLoad() {
     this.fetchCityList()
     this.set_new_alphabet(this.data.all_cities)
-
+    this.setData({
+      city: app.globalData.city,
+      historyCity: app.globalData.historyCity
+    })
     // var that = this
     //初始化
 
@@ -41,12 +52,20 @@ Page({
     // wxaSortPicker.init(this.data.cities, that);
   },
   onReady() {
-
+    wx.getSystemInfo({
+      success:  (res)=> {
+        // 获取可使用窗口宽度
+        let clientHeight = res.windowHeight;
+        // 设置高度
+        this.setData({
+          clientHeight: clientHeight
+        });
+      }
+    });
   },
   onShow() {
-    this.setData({
-      city: app.globalData.city
-    })
+
+
     _animation = wx.createAnimation({
       duration: 1000,
       timingFunction: 'linear', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
@@ -61,9 +80,10 @@ Page({
     })
     wx.createSelectorQuery().select('.select-box').boundingClientRect((res_b) => {
       // let b_top = res_b.top
+      
       this.setData({
-        b_top: res_b.top
-
+        b_top: res_b.top,
+        sliderHeight:this.data.clientHeight - res_b.top
       })
 
       let tab = this.data.new_cities
@@ -71,7 +91,7 @@ Page({
 
       for (let i = 0; i < tab.length; i++) {
         wx.createSelectorQuery().select('#item' + i).boundingClientRect((res_i) => {
-          console.log(res_i)
+          // console.log(res_i)
           tab[i].top = res_i.top - this.data.b_top;
           this.setData({
             new_cities: tab,
@@ -95,7 +115,6 @@ Page({
       // console.log(e.detail.scrollTop)
       let scrollTop = e.detail.scrollTop
       let tabs = this.data.new_cities
-      console.log(scrollTop, this.data.b_top, tabs[tabs.length - 1].top)
 
       for (let i = 0; i < tabs.length; i++) {
         if (scrollTop > tabs[i].top && scrollTop < tabs[i + 1].top) {
@@ -103,7 +122,7 @@ Page({
             apl_index: tabs[i].alphabetIndex
           })
           // console.log(tabs[i].alphabetIndex)
-        } else if (scrollTop + this.data.b_top+30 >= tabs[tabs.length - 1].top) {
+        } else if (scrollTop + this.data.b_top + 30 >= tabs[tabs.length - 1].top) {
           console.log('到底了')
           this.setData({
             apl_index: tabs[tabs.length - 1].alphabetIndex
@@ -187,6 +206,7 @@ Page({
     } = e.currentTarget.dataset
     // app.globalData.city = city.replace('市', '')
     app.globalData.city = city
+    this.set_historyCity(city)
     wx.navigateBack()
   },
   selectLocation() {
@@ -279,5 +299,22 @@ Page({
     })
 
   },
+  set_historyCity(city) {
+    if (!app.globalData.historyCity.includes(city)) {
+      app.globalData.historyCity.push(city)
+      saveHistoryCity(app.globalData.historyCity)
+      this.setData({
+        historyCity: app.globalData.historyCity
+      })
+    }
+  },
+  remove_historyCity() {
+    removeHistoryCity()
+    app.globalData.historyCity = loadHistoryCity() || []
+    this.setData({
+      historyCity: loadHistoryCity() || []
+    })
+
+  }
 
 })

+ 6 - 5
apps/RealtorEasier/pages/city/city.wxml

@@ -28,18 +28,19 @@
 <view class="histroy-city">
     <view class="history-title">
         <view class="city-label">浏览记录</view>
-        <text class="hitstroy-destory">清空</text>
+        <text bindtap="remove_historyCity" class="hitstroy-destory">清空</text>
     </view>
 
     <view class="histroy-box">
-        <view class="history-item">纽约纽约纽约纽约</view>
-        <view class="history-item">纽约</view>
-        <view class="history-item">纽约</view>
+        <view class="history-item" data-city="{{item}}"
+                            bindtap="handleCityClick" wx:for="{{historyCity}}">{{item}}</view>
+        <!-- <view class="history-item">纽约</view>
+        <view class="history-item">纽约</view> -->
     </view>
 </view>
 
 <view class="city-label">全部城市</view>
-<view class="select-box">
+<view class="select-box" style="height:{{sliderHeight}}px;">
     <view class="btn_jump">
         <view class="btn_item {{apl_index ==item.alphabetIndex ?'active':''}}" bindtap='jumpTo' data-index="{{item.alphabetIndex}}"  data-opt="item{{idx}}" wx:for="{{new_cities}}" wx:for-index="idx">
             {{alphabet[item.alphabetIndex]}}</view>

Разница между файлами не показана из-за своего большого размера
+ 8 - 5
apps/RealtorEasier/pages/city/city.wxss


+ 1 - 10
apps/RealtorEasier/pages/city/json/cities.js

@@ -209,16 +209,7 @@ var cities = [
           "code_full":"USA0COASE",
           "FirstLetter":"A"
       },
-      {
-          "id":"3397",
-          "state_id":"214",
-          "code":"AUX",
-          "name":"Aurora",
-          "cname":"奥罗拉",
-          "lower_name":"aurora",
-          "code_full":"USA0COAUX",
-          "FirstLetter":"A"
-      },
+      
       {
           "id":"3398",
           "state_id":"214",

+ 9 - 2
apps/RealtorEasier/pages/index/index.wxss

@@ -40,20 +40,27 @@
   align-items: center;
   max-width: 230rpx;
   min-width: 158rpx;
+  display: flex;
+  align-items: center;
 }
+
 .location-icon {
   width: 26rpx;
   height: 30rpx;
   margin-right: 10rpx;
 }
 .action view {
-  display:-webkit-box;
+  /* display:-webkit-box;
   -webkit-box-orient:vertical;
   -webkit-line-clamp: 1;
   text-overflow: ellipsis;
   overflow: hidden;
   word-break: break-all;
-  flex: 1;
+  flex: 1; */
+  max-width: 150rpx;
+  white-space:nowrap;
+  overflow: hidden;
+  text-overflow: ellipsis;
 }
 .icon-list{
   display: flex;

+ 32 - 14
apps/RealtorEasier/utils/storage.js

@@ -3,8 +3,9 @@ const USER_INFO_KEY = 'wx_user_info'
 const USER_CODE_KEY = 'wx_user_code'
 const TOKEN_KEY = 'wx_token'
 const VIEW_HISTORY_KEY = 'view_history'
+const CITY_HISTORY = 'city_history'
 
-function saveStorage (key, value, expired = 0) {
+function saveStorage(key, value, expired = 0) {
   const storage = {
     value
   }
@@ -19,7 +20,7 @@ function saveStorage (key, value, expired = 0) {
   }
 }
 
-function loadStorage (key) {
+function loadStorage(key) {
   try {
     const storage = wx.getStorageSync(key)
     // 过期
@@ -33,7 +34,7 @@ function loadStorage (key) {
   }
 }
 
-function removeStorage (key) {
+function removeStorage(key) {
   try {
     return wx.removeStorageSync(key)
   } catch (e) {
@@ -41,50 +42,67 @@ function removeStorage (key) {
   }
 }
 
-export function saveUserInfo (userinfo) {
+export function saveUserInfo(userinfo) {
   return saveStorage(USER_INFO_KEY, userinfo, 86400 / 24)
 }
 
-export function loadUserInfo () {
+export function loadUserInfo() {
   return loadStorage(USER_INFO_KEY)
 }
 
 
-export function removeUserInfo () {
+export function removeUserInfo() {
   return removeStorage(USER_INFO_KEY)
 }
-export function saveUserCode (usercode) {
+export function saveUserCode(usercode) {
   return saveStorage(USER_CODE_KEY, usercode, 86400 / 24)
 }
 
-export function loadUserCode () {
+export function loadUserCode() {
   return loadStorage(USER_CODE_KEY)
 }
 
 
-export function removeUserCode () {
+export function removeUserCode() {
   return removeStorage(USER_CODE_KEY)
 }
 
-export function saveToken (token) {
+export function saveToken(token) {
   return saveStorage(TOKEN_KEY, token, 86400 / 24)
 }
 
-export function loadToken () {
+export function loadToken() {
   return loadStorage(TOKEN_KEY)
 }
 
-export function removeToken () {
+export function removeToken() {
   return removeStorage(TOKEN_KEY)
 }
 
-export function saveViewHistory (house) {
+export function saveViewHistory(house) {
   let historys = loadViewHistory() || []
   historys = historys.filter(item => item.house_id !== house.house_id)
   historys.unshift(house)
   return saveStorage(VIEW_HISTORY_KEY, historys)
 }
 
-export function loadViewHistory () {
+export function loadViewHistory() {
   return loadStorage(VIEW_HISTORY_KEY)
+}
+
+export function saveHistoryCity(arr) {
+  return saveStorage(CITY_HISTORY, JSON.stringify(arr))
+}
+
+export function loadHistoryCity() {
+  try {
+    return JSON.parse(loadStorage(CITY_HISTORY))
+
+  } catch (err) {
+    return loadStorage(CITY_HISTORY)
+
+  }
+}
+export function removeHistoryCity() {
+  return removeStorage(CITY_HISTORY)
 }