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.mzph.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命令修…