Flask愛家租房--房屋管理(獲取主頁幻燈片展示的房屋基本信息)

文章目錄

  • 0.效果展示
  • 1.重點總結
  • 2.后端代碼
  • 3.前端js
  • 4.前端html

0.效果展示

在這里插入圖片描述

1.重點總結

1)當用戶訪問首頁時,開始加載頁面信息,此時index.js文件首先調用后端接口check_login(),判斷用戶是否登錄,未登錄則在右上角關聯注冊和登錄相關接口;
在這里插入圖片描述
在這里插入圖片描述
登錄則顯示用戶名相關信息;
在這里插入圖片描述
2)接下來,想要獲取數據,需要根據index.js文件,調用獲取主頁幻燈片展示的房屋基本信息的接口get_house_index();
在這里插入圖片描述
在這里插入圖片描述
并將json格式的數據返回給index.js文件;
在這里插入圖片描述3)index.js文件將數據推送給前端類名為swiper-wrapper部分;
在這里插入圖片描述在這里插入圖片描述
前端得到數據后,想要將數據轉換成幻燈片形式進行放映,需要swiper.jquery.min.js文件;
在這里插入圖片描述后端index.js文件創建此容器,并對容器相關設置進行規定;容器接受數據,將房屋信息展示出來。
在這里插入圖片描述

2.后端代碼

house.py部分接口:

@api.route("/houses/index", methods=["GET"])
def get_house_index():"""獲取主頁幻燈片展示的房屋基本信息"""# 從緩存中嘗試獲取數據try:ret = redis_store.get("home_page_data")except Exception as e:current_app.logger.error(e)ret = Noneif ret:current_app.logger.info("hit house index info redis")# 因為redis中保存的是json字符串,所以直接進行字符串拼接返回return '{"errno":0, "errmsg":"OK", "data":%s}' % ret, 200, {"Content-Type": "application/json"}else:try:# 查詢數據庫,返回房屋訂單數目最多的5條數據houses = House.query.order_by(House.order_count.desc()).limit(constants.HOME_PAGE_MAX_HOUSES)except Exception as e:current_app.logger.error(e)return jsonify(errno=RET.DBERR, errmsg="查詢數據失敗")if not houses:return jsonify(errno=RET.NODATA, errmsg="查詢無數據")houses_list = []for house in houses:# 如果房屋未設置主圖片,則跳過if not house.index_image_url:continuehouses_list.append(house.to_basic_dict())# 將數據轉換為json,并保存到redis緩存json_houses = json.dumps(houses_list)  # "[{},{},{}]"try:redis_store.setex("home_page_data", constants.HOME_PAGE_DATA_REDIS_EXPIRES, json_houses)except Exception as e:current_app.logger.error(e)return '{"errno":0, "errmsg":"OK", "data":%s}' % json_houses, 200, {"Content-Type": "application/json"}

3.前端js

index.js

 //模態框居中的控制
function centerModals(){$('.modal').each(function(i){   //遍歷每一個模態框var $clone = $(this).clone().css('display', 'block').appendTo('body');    var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);top = top > 0 ? top : 0;$clone.remove();$(this).find('.modal-content').css("margin-top", top-30);  //修正原先已經有的30個像素});
}function setStartDate() {var startDate = $("#start-date-input").val();if (startDate) {$(".search-btn").attr("start-date", startDate);$("#start-date-btn").html(startDate);$("#end-date").datepicker("destroy");$("#end-date-btn").html("離開日期");$("#end-date-input").val("");$(".search-btn").attr("end-date", "");$("#end-date").datepicker({language: "zh-CN",keyboardNavigation: false,startDate: startDate,format: "yyyy-mm-dd"});$("#end-date").on("changeDate", function() {$("#end-date-input").val($(this).datepicker("getFormattedDate"));});$(".end-date").show();}$("#start-date-modal").modal("hide");
}function setEndDate() {var endDate = $("#end-date-input").val();if (endDate) {$(".search-btn").attr("end-date", endDate);$("#end-date-btn").html(endDate);}$("#end-date-modal").modal("hide");
}function goToSearchPage(th) {var url = "/search.html?";url += ("aid=" + $(th).attr("area-id"));url += "&";var areaName = $(th).attr("area-name");if (undefined == areaName) areaName="";url += ("aname=" + areaName);url += "&";url += ("sd=" + $(th).attr("start-date"));url += "&";url += ("ed=" + $(th).attr("end-date"));location.href = url;
}$(document).ready(function(){// 檢查用戶的登錄狀態$.get("/api/v1.0/session", function(resp) {if ("0" == resp.errno) {$(".top-bar>.user-info>.user-name").html(resp.data.name);$(".top-bar>.user-info").show();} else {$(".top-bar>.register-login").show();}}, "json");// 獲取幻燈片要展示的房屋基本信息$.get("/api/v1.0/houses/index", function(resp){if ("0" == resp.errno) {$(".swiper-wrapper").html(template("swiper-houses-tmpl", {houses:resp.data}));// 設置幻燈片對象,開啟幻燈片滾動var mySwiper = new Swiper ('.swiper-container', {loop: true,autoplay: 2000,autoplayDisableOnInteraction: false,pagination: '.swiper-pagination',paginationClickable: true});}});// 獲取城區信息$.get("/api/v1.0/areas", function(resp){if ("0" == resp.errno) {$(".area-list").html(template("area-list-tmpl", {areas:resp.data}));$(".area-list a").click(function(e){$("#area-btn").html($(this).html());$(".search-btn").attr("area-id", $(this).attr("area-id"));$(".search-btn").attr("area-name", $(this).html());$("#area-modal").modal("hide");});}});$('.modal').on('show.bs.modal', centerModals);      //當模態框出現的時候$(window).on('resize', centerModals);               //當窗口大小變化的時候$("#start-date").datepicker({language: "zh-CN",keyboardNavigation: false,startDate: "today",format: "yyyy-mm-dd"});$("#start-date").on("changeDate", function() {var date = $(this).datepicker("getFormattedDate");$("#start-date-input").val(date);});
})

4.前端html

index.html

<!DOCTYPE html>
<html>
<head> <meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"><title>愛家</title><link href="/static/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet"><link href="/static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"><link href="/static/css/reset.css" rel="stylesheet"><link href="/static/plugins/swiper/css/swiper.min.css" rel="stylesheet"><link href="/static/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet"><link href="/static/css/ihome/main.css" rel="stylesheet"><link href="/static/css/ihome/index.css" rel="stylesheet">
</head>
<body><div class="container"><div class="top-bar"><img class="logo fl" src="/static/images/logo@128x59.png"><div class="register-login fr"><a class="btn top-btn btn-theme" href="/register.html">注冊</a><a class="btn top-btn btn-theme" href="/login.html">登錄</a></div><div class="user-info fr"><span><i class="fa fa-user fa-lg"></i></span> <a class="user-name" href="/my.html"></a></div></div><div class="swiper-container"><div class="swiper-wrapper"></div><script id="swiper-houses-tmpl" type="text/html">{{each houses as house}}<div class="swiper-slide"><a href="/detail.html?id={{house.house_id}}"><img src="{{house.img_url}}"></a><div class="slide-title">{{house.title}}</div></div>{{/each}}</script><div class="swiper-pagination"></div></div><div class="search-bar"><button class="filter-btn" type="button" data-toggle="modal" data-target="#area-modal"><span class="fl" id="area-btn">選擇城區</span><span class="fr"><i class="fa fa-map-marker fa-lg fa-fw"></i></span></button><button class="filter-btn" type="button" data-toggle="modal" data-target="#start-date-modal"><span class="fl" id="start-date-btn">入住日期</span><span class="fr"><i class="fa fa-calendar fa-lg fa-fw"></i></span></button><button class="filter-btn end-date" type="button" data-toggle="modal" data-target="#end-date-modal"><span class="fl" id="end-date-btn">離開日期</span><span class="fr"><i class="fa fa-calendar fa-lg fa-fw"></i></span></button><a class="btn search-btn btn-theme" href="#" onclick="goToSearchPage(this);" area-id="" start-date="" end-date="">搜索</a><div class="modal fade" id="area-modal" tabindex="-1" role="dialog" aria-labelledby="area-label"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h4 class="modal-title" id="area-label">選擇城區</h4></div><div class="modal-body"><div class="area-list"></div><script id="area-list-tmpl" type="text/html">{{each areas as area}}<a href="#" area-id="{{area.aid}}">{{area.aname}}</a>{{/each}}</script></div></div></div></div><div class="modal fade" id="start-date-modal" tabindex="-1" role="dialog" aria-labelledby="start-date-label"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h4 class="modal-title" id="start-date-label">入住日期</h4></div><div class="modal-body"><div class="date-select" id="start-date"></div><input type="hidden" id="start-date-input"></div><div class="modal-footer"><button type="button" class="btn btn-theme" onclick="setStartDate();">確定</button></div></div></div></div><div class="modal fade" id="end-date-modal" tabindex="-1" role="dialog" aria-labelledby="end-date-label"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h4 class="modal-title" id="end-date-label">離開日期</h4></div><div class="modal-body"><div class="date-select" id="end-date"></div><input type="hidden" id="end-date-input"></div><div class="modal-footer"><button type="button" class="btn btn-theme" onclick="setEndDate();">確定</button></div></div></div></div></div><div class="footer"><p><span><i class="fa fa-copyright"></i></span>愛家租房&nbsp;&nbsp;享受家的溫馨</p></div></div><script src="/static/js/jquery.min.js"></script><script src="/static/plugins/bootstrap/js/bootstrap.min.js"></script><script src="/static/plugins/swiper/js/swiper.jquery.min.js"></script><script src="/static/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script><script src="/static/plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script><script src="/static/js/template.js"></script><script src="/static/js/ihome/index.js"></script>
</body>
</html>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/452595.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/452595.shtml
英文地址,請注明出處:http://en.pswp.cn/news/452595.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

C#題目及答案(1)

1. 簡述 private、 protected、 public、 internal 修飾符的訪問權限。 答 . private : 私有成員, 在類的內部才可以訪問。 protected : 保護成員,該類內部和繼承類中可以訪問。 public : 公共成員,完全公開,沒有訪問限制。 internal: 在同一命名空間內可以訪問。 2 .列舉ASP.N…

linux bash函數里面調用命令行,Linux-在gnome-terminal -x中運行bash函數

您可以將其與export -f一起使用,就像kojiro的上面的注釋中指出的那樣.# Define function.my_func() {// Do cool stuff}# Export it, so that all child bash processes see it.export -f my_func# Invoke gnome-terminal with bash -c and the function name, *plus*# another…

隨想錄(軟件開發不能是加工作坊)

前一段時間看了一本《走出軟件作坊》&#xff0c;心情很沉重。不管你是否承認&#xff0c;書中描述的情況在現在的國內IT企業中確實存在&#xff0c;可能涉及的范圍還很廣。聯想到自己目前處于的行業&#xff0c;心中不免唏噓不已。類似的事件&#xff0c;類似的方法&#xff0…

程序員的核心競爭力

1、穩定的基礎知識體系&#xff1b; 2、需求到模型的轉化建模能力&#xff1b; 3、獨立思考能力&#xff1b; 4、思想&#xff1a;世界觀、方法論。

Flask愛家租房--訂單支付(支付過程)

文章目錄0.支付流程1. 重點總結2.后端代碼3.前端js4.前端html0.支付流程 1. 重點總結 1&#xff09;用戶進入“我的訂單”頁面&#xff0c;點擊“去支付”&#xff1b; 觸發后端js中的函數&#xff0c;發出ajsx異步請求&#xff0c;調用后端相應接口order_pay(order_id)&#…

微信小程序利用key實現列表性能的提升

微信小程序利用key實現列表性能的提升 key值在列表渲染的時候&#xff0c;能夠提升列表渲染性能&#xff0c;為什么呢&#xff1f;首先得想想小程序的頁面是如何渲染的&#xff0c;主要分為以下幾步&#xff1a; 將wxml結構的文檔構建成一個vdom虛擬數頁面有新的交互&#xff0…

CentOS MySQL 5.7編譯安裝

CentOS MySQL 5.7編譯安裝 MySQL 5.7 GA版本的發布&#xff0c;也就是說從現在開始5.7已經可以在生產環境中使用&#xff0c;有任何問題官方都將立刻修復。 MySQL 5.7主要特性&#xff1a; 更好的性能&#xff1a;對于多核CPU、固態硬盤、鎖有著更好的優化&#xff0c;每秒100…

為什么設計師創造的編程語言更受歡迎?

導讀&#xff1a;在編程的世界里&#xff0c;語言紛繁多樣&#xff0c;而大部分真正廣泛流行的語言并不是那些學術界的產物&#xff0c;而是在通過自由發揮設計出來的。 和那些在最后期限重壓下產生的語言版本比較起來&#xff0c;從一定程度上來看&#xff0c;從學術界產生出…

狀態轉換圖簡介

狀態轉換圖(簡稱為狀態圖)通過描繪系統的狀態及引起系統狀態轉換的事件&#xff0c;來表示系統的行為。此外&#xff0c;狀態圖還指明了作為特定事件的結果系統將做哪些動作。 &#xff08;一&#xff09;狀態 狀態是任何可以被觀察到的系統行為模式&#xff0c;一個狀態代表…

C#常用單元測試框架比較:XUnit、NUnit和Visual Studio(MSTest)

做過單元測試的同學大概都知道以上幾種測試框架&#xff0c;但我一直很好奇它們到底有什么不同&#xff0c;然后搜到了一篇不錯的文章清楚地解釋了這幾種框架的最大不同之處。 地址在這里&#xff1a;http://www.tuicool.com/articles/F3eEn2j 簡而言之&#xff0c;三者是非常相…

實驗五 類和對象-3

1.ex3.cpp 1 #include <iostream>2 #include <vector>3 #include <string>4 using namespace std;5 6 // 函數聲明 7 void output1(vector<string> &); 8 void output2(vector<string> &); 9 10 int main() 11 { 12 vector<st…

Vector用法詳解

這篇文章的目的是為了介紹std::vector&#xff0c;如何恰當地使用它們的成員函數等操作。本文中還討論了條件函數和函數指針在迭代算法中使用&#xff0c;如在remove_if()和for_each()中的使用。通過閱讀這篇文章讀者應該能夠有效地使用vector容器&#xff0c;而且應該不會再去…

linux 共享移動硬盤,隨時登陸上QQ 自帶Linux移動硬盤實戰

在以往我們的觀念中&#xff0c;移動硬盤頂多就是個移動存儲設備&#xff0c;根本談不上有什么功能&#xff0c;但今天這款一盤通卻將我們原始的觀念打了一個180大轉彎&#xff01;如果你的電腦支持USB設備啟動&#xff0c;那么只需要在BIOS進行一下更改&#xff0c;一盤通就可…

需求分析的圖形工具(層次方框 warnier IPO)

1 層次方框圖 層次方框圖用樹形結構的一系列多層次的矩形框描繪數據的層次結構。 例如&#xff0c;描繪一家計算機公司全部產品的數據結構可以用下圖層次方框圖表示。 這家公司的產品由硬件、軟件和服務3類產品組成&#xff0c;軟件產品又分為系統軟件和應用軟件&#xf…

如何處理錯誤信息 Pricing procedure could not be determined

2019獨角獸企業重金招聘Python工程師標準>>> 當給一個SAP CRM Quotation文檔的行項目維護一個產品時&#xff0c;遇到如下錯誤信息&#xff1a;Pricing procedure could not be determined 通過調試得知錯誤消息在function module CRM_PRIDOC_COM_PRCPROC_DET_SEL第…

Flask愛家租房--訂單(下訂單)

文章目錄0 、效果展示1、思路總結2、后端代碼3、前端js4、前端html0 、效果展示 detail.html booking.html 1、思路總結 1&#xff09;用戶打開房屋詳情頁detail.html之后&#xff0c;后端detail.js會判斷此訪問用戶是否為房東&#xff0c;若不是房東&#xff0c;則在詳情…

linux下各權限的細分

PS&#xff1a;有時候你發現用root權限都不能修改某個文件&#xff0c;大部分原因是曾經用chattr命令鎖定該文件了。chattr命令的作用很大&#xff0c;其中一些功能是由Linux內核版本來支持的&#xff0c;不過現在生產絕大部分跑的linux系統都是2.6以上內核了。通過chattr命令修…