国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁(yè) web前端 js教程 從零到店面:我建立汽車租賃網(wǎng)站和行動(dòng)應(yīng)用程式的旅程

從零到店面:我建立汽車租賃網(wǎng)站和行動(dòng)應(yīng)用程式的旅程

Nov 26, 2024 am 12:26 AM

內(nèi)容

  1. 簡(jiǎn)介
  2. 技術(shù)堆疊
  3. 快速概覽
  4. API
  5. 前端
  6. 行動(dòng)應(yīng)用程式
  7. 管理儀表板
  8. 興趣點(diǎn)
  9. 資源

原始碼:https://github.com/aelassas/bookcars

示範(fàn):https://bookcars.dynv6.net:3002

介紹

這個(gè)想法源於建立無(wú)邊界的願(yuàn)望 - 一個(gè)完全可定制的汽車租賃網(wǎng)站和行動(dòng)應(yīng)用程序,其中每個(gè)方面都在您的控制之下:

  • 擁有 UI/UX:設(shè)計(jì)獨(dú)特的客戶體驗(yàn),而無(wú)需克服模板限制
  • 控制後端:實(shí)現(xiàn)完美匹配需求的自訂業(yè)務(wù)邏輯和資料結(jié)構(gòu)
  • 掌握 DevOps:使用首選工具和工作流程部署、擴(kuò)展和監(jiān)控應(yīng)用程式
  • 自由擴(kuò)充:增加新功能和集成,無(wú)需平臺(tái)限製或額外費(fèi)用

技術(shù)堆疊

這是使其成為可能的技術(shù)堆疊:

  • 打字稿
  • Node.js
  • MongoDB
  • 反應(yīng)
  • MUI
  • React Native
  • 世博會(huì)
  • 條紋
  • 碼頭工人

由於 TypeScript 具有眾多優(yōu)點(diǎn),因此做出了使用 TypeScript 的關(guān)鍵設(shè)計(jì)決定。 TypeScript 提供強(qiáng)大的類型、工具和集成,從而產(chǎn)生高品質(zhì)、可擴(kuò)展、更具可讀性和可維護(hù)性的程式碼,並且易於調(diào)試和測(cè)試。

我選擇React是因?yàn)樗鼜?qiáng)大的渲染能力,MongoDB是為了靈活的資料建模,而Stripe是為了安全的支付處理。

選擇此堆疊,您不僅僅是在建立網(wǎng)站和行動(dòng)應(yīng)用程式 - 您正在投資一個(gè)可以根據(jù)您的需求不斷發(fā)展的基礎(chǔ),並得到強(qiáng)大的開(kāi)源技術(shù)和不斷發(fā)展的開(kāi)發(fā)者社群的支持。

React 因其以下優(yōu)點(diǎn)而成為絕佳選擇:

  1. 基於組件的架構(gòu)
    • 讓您將複雜的 UI 分解為更小的、可重複使用的部分
    • 使程式碼更易於維護(hù)且更易於測(cè)試
    • 實(shí)現(xiàn)更好的程式碼組織和可重複使用性
  2. 虛擬 DOM 效能
    • React 的虛擬 DOM 有效率地僅更新必要的內(nèi)容
    • 帶來(lái)更快的頁(yè)面載入和更好的使用者體驗(yàn)
    • 減少不必要的重新渲染
  3. 豐富的生態(tài)系統(tǒng)
    • 龐大的預(yù)建元件庫(kù)
    • 豐富的工具
    • 提供支持和資源的大型社區(qū)
  4. 豐富的開(kāi)發(fā)人員經(jīng)驗(yàn)
    • 熱重載以取得即時(shí)回饋
    • 優(yōu)秀的調(diào)試工具
    • JSX 讓寫 UI 程式碼更直覺(jué)
  5. 業(yè)界支持
    • 由 Meta(以前的 Facebook)支援
    • 被許多大公司使用
    • 持續(xù)開(kāi)發(fā)與改進(jìn)
  6. 靈活性
    • 適用於小型和大型應(yīng)用程式
    • 可以逐步整合到現(xiàn)有專案中
    • 支援多種渲染策略(客戶端、服務(wù)端、靜態(tài))

快速概覽

在本部分中,您將看到前端、管理儀表板和行動(dòng)應(yīng)用程式的主頁(yè)。

前端

在前端,使用者可以搜尋可用的汽車、選擇汽車並結(jié)帳。

下面是前端主頁(yè),使用者可以選擇上下車地點(diǎn)和時(shí)間,並搜尋可用的車輛。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是主頁(yè)的搜尋結(jié)果,用戶可以在其中選擇租車。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

下面是結(jié)帳頁(yè)面,使用者可以在其中設(shè)定租賃選項(xiàng)和結(jié)帳。如果用戶未註冊(cè),可以同時(shí)結(jié)帳和註冊(cè)。如果他尚未註冊(cè),他將收到一封確認(rèn)和啟動(dòng)電子郵件以設(shè)定密碼。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是登入頁(yè)面。在生產(chǎn)中,身份驗(yàn)證 cookie 是 httpOnly、簽署的、安全且嚴(yán)格的 sameSite。?這些選項(xiàng)可防止 XSS、CSRF 和 MITM 攻擊。?身份驗(yàn)證 cookie 也可以透過(guò)自訂中間件免受 XST 攻擊。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是註冊(cè)頁(yè)面。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是使用者可以查看和管理他的預(yù)訂的頁(yè)面。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

下面是用戶可以查看預(yù)訂詳細(xì)資訊的頁(yè)面。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是聯(lián)絡(luò)頁(yè)面。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是租車地點(diǎn)頁(yè)。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是客戶可以查看和管理他的通知的頁(yè)面。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

還有其他頁(yè)面,但這些是前端的主要頁(yè)面。

管理儀表板

使用者分為三種:

  • 管理員:他擁有管理儀表板的完全存取權(quán)。他什麼都能做。
  • 供應(yīng)商:他對(duì)管理儀表板的存取權(quán)限受到限制。他只能管理他的汽車和預(yù)訂。
  • 使用者:他只能存取前端和行動(dòng)應(yīng)用程式。他無(wú)法存取管理儀表板。

該平臺(tái)旨在與多個(gè)供應(yīng)商合作。每個(gè)供應(yīng)商都可以從管理儀表板管理他的車隊(duì)和預(yù)訂。該平臺(tái)也可以只與一個(gè)供應(yīng)商合作。

透過(guò)管理儀表板,管理員使用者可以建立和管理供應(yīng)商、汽車、位置、使用者和預(yù)訂。

當(dāng)管理員使用者建立新供應(yīng)商時(shí),供應(yīng)商將收到一封自動(dòng)電子郵件,用於建立他的帳戶以存取管理儀表板,以便他可以管理他的車隊(duì)和預(yù)訂。

以下是管理儀表板的登入頁(yè)面。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是管理儀表板的儀表板頁(yè)面,管理員和供應(yīng)商可以在其中查看和管理預(yù)訂。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是車隊(duì)展示和管理的頁(yè)面。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是管理員和供應(yīng)商可以透過(guò)提供圖像和汽車資訊來(lái)建立新車的頁(yè)面。對(duì)於免費(fèi)包含的汽車選項(xiàng),請(qǐng)將相應(yīng)的汽車選項(xiàng)設(shè)為 0。否則,請(qǐng)?jiān)O(shè)定選項(xiàng)的價(jià)格,如果您不想包含它,請(qǐng)將其留空。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是管理員和供應(yīng)商可以編輯汽車的頁(yè)面。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是管理員可以管理平臺(tái)使用者的頁(yè)面。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

以下是編輯預(yù)訂的頁(yè)面。

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

還有其他頁(yè)面,但這些是管理儀表板的主頁(yè)。

應(yīng)用程式介面

From Zero to Storefront: My Journey Building a Car Rental Website and Mobile App

API 公開(kāi)了管理儀表板、前端和行動(dòng)應(yīng)用程式所需的所有功能。 API遵循MVC設(shè)計(jì)模式。 JWT 用於身份驗(yàn)證。有些功能需要身份驗(yàn)證,例如與管理汽車、預(yù)訂和客戶相關(guān)的功能,而其他功能則不需要身份驗(yàn)證,例如為未經(jīng)過(guò)身份驗(yàn)證的用戶檢索位置和可用汽車:

  • ./api/src/models/ 資料夾包含 MongoDB 模型。
  • ./api/src/routes/ 資料夾包含 Express 路線。
  • ./api/src/controllers/ 資料夾包含控制器。
  • ./api/src/middlewares/ 資料夾包含中間件。
  • ./api/src/config/env.config.ts 包含設(shè)定和 TypeScript 類型定義。
  • ./api/src/lang/ 資料夾包含在地化內(nèi)容。
  • ./api/src/app.ts 是載入路由的主伺服器。
  • ./api/index.ts 是 api 的主要入口點(diǎn)。

index.ts 是 api 的主要入口點(diǎn):

import 'dotenv/config'
import process from 'node:process'
import fs from 'node:fs/promises'
import http from 'node:http'
import https, { ServerOptions } from 'node:https'
import * as env from './config/env.config'
import * as databaseHelper from './common/databaseHelper'
import app from './app'
import * as logger from './common/logger'

if (
  await databaseHelper.connect(env.DB_URI, env.DB_SSL, env.DB_DEBUG)
  && await databaseHelper.initialize()
) {
  let server: http.Server | https.Server

  if (env.HTTPS) {
    https.globalAgent.maxSockets = Number.POSITIVE_INFINITY
    const privateKey = await fs.readFile(env.PRIVATE_KEY, 'utf8')
    const certificate = await fs.readFile(env.CERTIFICATE, 'utf8')
    const credentials: ServerOptions = { key: privateKey, cert: certificate }
    server = https.createServer(credentials, app)

    server.listen(env.PORT, () => {
      logger.info('HTTPS server is running on Port', env.PORT)
    })
  } else {
    server = app.listen(env.PORT, () => {
      logger.info('HTTP server is running on Port', env.PORT)
    })
  }

  const close = () => {
    logger.info('Gracefully stopping...')
    server.close(async () => {
      logger.info(`HTTP${env.HTTPS ? 'S' : ''} server closed`)
      await databaseHelper.close(true)
      logger.info('MongoDB connection closed')
      process.exit(0)
    })
  }

  ['SIGINT', 'SIGTERM', 'SIGQUIT'].forEach((signal) => process.on(signal, close))
}

這是一個(gè)使用 Node.js 和 Express 啟動(dòng)伺服器的 TypeScript 檔案。它導(dǎo)入了多個(gè)模組,包括 dotenv、process、fs、http、https、mongoose 和 app。然後,它檢查 HTTPS 環(huán)境變數(shù)是否設(shè)為 true,如果是,則使用 https 模組以及提供的私密金鑰和憑證建立 HTTPS 伺服器。否則,它使用 http 模組建立一個(gè) HTTP 伺服器。伺服器監(jiān)聽(tīng) PORT 環(huán)境變數(shù)中指定的連接埠。

close 函數(shù)被定義為在收到終止訊號(hào)時(shí)優(yōu)雅地停止伺服器。它關(guān)閉伺服器和 MongoDB 連接,然後以狀態(tài)碼 0 退出進(jìn)程。最後,它註冊(cè)當(dāng)進(jìn)程收到 SIGINT、SIGTERM 或 SIGQUIT 訊號(hào)時(shí)要呼叫的 close 函數(shù)。

app.ts 是 api 的主要入口點(diǎn):

import express from 'express'
import compression from 'compression'
import helmet from 'helmet'
import nocache from 'nocache'
import cookieParser from 'cookie-parser'
import i18n from './lang/i18n'
import * as env from './config/env.config'
import cors from './middlewares/cors'
import allowedMethods from './middlewares/allowedMethods'
import supplierRoutes from './routes/supplierRoutes'
import bookingRoutes from './routes/bookingRoutes'
import locationRoutes from './routes/locationRoutes'
import notificationRoutes from './routes/notificationRoutes'
import carRoutes from './routes/carRoutes'
import userRoutes from './routes/userRoutes'
import stripeRoutes from './routes/stripeRoutes'
import countryRoutes from './routes/countryRoutes'
import * as helper from './common/helper'

const app = express()

app.use(helmet.contentSecurityPolicy())
app.use(helmet.dnsPrefetchControl())
app.use(helmet.crossOriginEmbedderPolicy())
app.use(helmet.frameguard())
app.use(helmet.hidePoweredBy())
app.use(helmet.hsts())
app.use(helmet.ieNoOpen())
app.use(helmet.noSniff())
app.use(helmet.permittedCrossDomainPolicies())
app.use(helmet.referrerPolicy())
app.use(helmet.xssFilter())
app.use(helmet.originAgentCluster())
app.use(helmet.crossOriginResourcePolicy({ policy: 'cross-origin' }))
app.use(helmet.crossOriginOpenerPolicy())

app.use(nocache())
app.use(compression({ threshold: 0 }))
app.use(express.urlencoded({ limit: '50mb', extended: true }))
app.use(express.json({ limit: '50mb' }))

app.use(cors())
app.options('*', cors())
app.use(cookieParser(env.COOKIE_SECRET))
app.use(allowedMethods)

app.use('/', supplierRoutes)
app.use('/', bookingRoutes)
app.use('/', locationRoutes)
app.use('/', notificationRoutes)
app.use('/', carRoutes)
app.use('/', userRoutes)
app.use('/', stripeRoutes)
app.use('/', countryRoutes)

i18n.locale = env.DEFAULT_LANGUAGE

await helper.mkdir(env.CDN_USERS)
await helper.mkdir(env.CDN_TEMP_USERS)
await helper.mkdir(env.CDN_CARS)
await helper.mkdir(env.CDN_TEMP_CARS)
await helper.mkdir(env.CDN_LOCATIONS)
await helper.mkdir(env.CDN_TEMP_LOCATIONS)

export default app

首先,我們檢索 MongoDB 連接字串,然後與 MongoDB 資料庫(kù)建立連線。然後我們創(chuàng)建一個(gè) Express 應(yīng)用程式並載入 cors、壓縮、頭盔和 nocache 等中間件。我們使用頭盔中間件庫(kù)設(shè)置了各種安全措施。我們也為應(yīng)用程式的不同部分匯入各種路線文件,例如 sellerRoutes、bookingRoutes、locationRoutes、notificationRoutes、carRoutes 和 userRoutes。最後,我們載入 Express 路線並匯出應(yīng)用程式。

api中有8條路由。每條路線都有自己的控制器,遵循 MVC 設(shè)計(jì)模式和 SOLID 原則。主要路線如下:

  • userRoutes:提供與使用者相關(guān)的REST功能
  • supplierRoutes:提供與供應(yīng)商相關(guān)的REST功能
  • countryRoutes:提供與國(guó)家相關(guān)的REST功能
  • locationRoutes:提供與位置相關(guān)的REST函數(shù)
  • carRoutes:提供與汽車相關(guān)的REST功能
  • bookingRoutes:提供與預(yù)訂相關(guān)的REST功能
  • notificationRoutes:提供與通知相關(guān)的REST功能
  • stripeRoutes:提供與Stripe支付網(wǎng)關(guān)相關(guān)的REST功能

我們不會(huì)一一解釋每條路線。我們將以 CountryRoutes 為例,看看它是如何製作的:

import express from 'express'
import routeNames from '../config/countryRoutes.config'
import authJwt from '../middlewares/authJwt'
import * as countryController from '../controllers/countryController'

const routes = express.Router()

routes.route(routeNames.validate).post(authJwt.verifyToken, countryController.validate)
routes.route(routeNames.create).post(authJwt.verifyToken, countryController.create)
routes.route(routeNames.update).put(authJwt.verifyToken, countryController.update)
routes.route(routeNames.delete).delete(authJwt.verifyToken, countryController.deleteCountry)
routes.route(routeNames.getCountry).get(authJwt.verifyToken, countryController.getCountry)
routes.route(routeNames.getCountries).get(authJwt.verifyToken, countryController.getCountries)
routes.route(routeNames.getCountriesWithLocations).get(countryController.getCountriesWithLocations)
routes.route(routeNames.checkCountry).get(authJwt.verifyToken, countryController.checkCountry)
routes.route(routeNames.getCountryId).get(authJwt.verifyToken, countryController.getCountryId)

export default routes

首先,我們建立一個(gè) Express Router。然後,我們使用名稱、方法、中間件和控制器來(lái)建立路由。

routeNames 包含countryRoutes 路線名稱:

const routes = {
  validate: '/api/validate-country',
  create: '/api/create-country',
  update: '/api/update-country/:id',
  delete: '/api/delete-country/:id',
  getCountry: '/api/country/:id/:language',
  getCountries: '/api/countries/:page/:size/:language',
  getCountriesWithLocations: '/api/countries-with-locations/:language/:imageRequired/:minLocations',
  checkCountry: '/api/check-country/:id',
  getCountryId: '/api/country-id/:name/:language',
}

export default routes

countryController 包含有關(guān)國(guó)家的主要業(yè)務(wù)邏輯。我們不會(huì)看到控制器的所有原始程式碼,因?yàn)樗喈?dāng)大,但我們將以創(chuàng)建控制器函數(shù)為例。

以下是國(guó)家模型:

import { Schema, model } from 'mongoose'
import * as env from '../config/env.config'

const countrySchema = new Schema<env.Country>(
  {
    values: {
      type: [Schema.Types.ObjectId],
      ref: 'LocationValue',
      required: [true, "can't be blank"],
      validate: (value: any): boolean => Array.isArray(value),
    },
  },
  {
    timestamps: true,
    strict: true,
    collection: 'Country',
  },
)

const Country = model<env.Country>('Country', countrySchema)

export default Country

下面是 env.Country TypeScript 類型:

export interface Country extends Document {
  values: Types.ObjectId[]
  name?: string
}

一個(gè)國(guó)家有多種價(jià)值觀。每種語(yǔ)言一個(gè)。預(yù)設(shè)支援英語(yǔ)和法語(yǔ)。

以下是 LocationValue 模型:

import 'dotenv/config'
import process from 'node:process'
import fs from 'node:fs/promises'
import http from 'node:http'
import https, { ServerOptions } from 'node:https'
import * as env from './config/env.config'
import * as databaseHelper from './common/databaseHelper'
import app from './app'
import * as logger from './common/logger'

if (
  await databaseHelper.connect(env.DB_URI, env.DB_SSL, env.DB_DEBUG)
  && await databaseHelper.initialize()
) {
  let server: http.Server | https.Server

  if (env.HTTPS) {
    https.globalAgent.maxSockets = Number.POSITIVE_INFINITY
    const privateKey = await fs.readFile(env.PRIVATE_KEY, 'utf8')
    const certificate = await fs.readFile(env.CERTIFICATE, 'utf8')
    const credentials: ServerOptions = { key: privateKey, cert: certificate }
    server = https.createServer(credentials, app)

    server.listen(env.PORT, () => {
      logger.info('HTTPS server is running on Port', env.PORT)
    })
  } else {
    server = app.listen(env.PORT, () => {
      logger.info('HTTP server is running on Port', env.PORT)
    })
  }

  const close = () => {
    logger.info('Gracefully stopping...')
    server.close(async () => {
      logger.info(`HTTP${env.HTTPS ? 'S' : ''} server closed`)
      await databaseHelper.close(true)
      logger.info('MongoDB connection closed')
      process.exit(0)
    })
  }

  ['SIGINT', 'SIGTERM', 'SIGQUIT'].forEach((signal) => process.on(signal, close))
}

以下是 env.LocationValue TypeScript 類型:

import express from 'express'
import compression from 'compression'
import helmet from 'helmet'
import nocache from 'nocache'
import cookieParser from 'cookie-parser'
import i18n from './lang/i18n'
import * as env from './config/env.config'
import cors from './middlewares/cors'
import allowedMethods from './middlewares/allowedMethods'
import supplierRoutes from './routes/supplierRoutes'
import bookingRoutes from './routes/bookingRoutes'
import locationRoutes from './routes/locationRoutes'
import notificationRoutes from './routes/notificationRoutes'
import carRoutes from './routes/carRoutes'
import userRoutes from './routes/userRoutes'
import stripeRoutes from './routes/stripeRoutes'
import countryRoutes from './routes/countryRoutes'
import * as helper from './common/helper'

const app = express()

app.use(helmet.contentSecurityPolicy())
app.use(helmet.dnsPrefetchControl())
app.use(helmet.crossOriginEmbedderPolicy())
app.use(helmet.frameguard())
app.use(helmet.hidePoweredBy())
app.use(helmet.hsts())
app.use(helmet.ieNoOpen())
app.use(helmet.noSniff())
app.use(helmet.permittedCrossDomainPolicies())
app.use(helmet.referrerPolicy())
app.use(helmet.xssFilter())
app.use(helmet.originAgentCluster())
app.use(helmet.crossOriginResourcePolicy({ policy: 'cross-origin' }))
app.use(helmet.crossOriginOpenerPolicy())

app.use(nocache())
app.use(compression({ threshold: 0 }))
app.use(express.urlencoded({ limit: '50mb', extended: true }))
app.use(express.json({ limit: '50mb' }))

app.use(cors())
app.options('*', cors())
app.use(cookieParser(env.COOKIE_SECRET))
app.use(allowedMethods)

app.use('/', supplierRoutes)
app.use('/', bookingRoutes)
app.use('/', locationRoutes)
app.use('/', notificationRoutes)
app.use('/', carRoutes)
app.use('/', userRoutes)
app.use('/', stripeRoutes)
app.use('/', countryRoutes)

i18n.locale = env.DEFAULT_LANGUAGE

await helper.mkdir(env.CDN_USERS)
await helper.mkdir(env.CDN_TEMP_USERS)
await helper.mkdir(env.CDN_CARS)
await helper.mkdir(env.CDN_TEMP_CARS)
await helper.mkdir(env.CDN_LOCATIONS)
await helper.mkdir(env.CDN_TEMP_LOCATIONS)

export default app

LocationValue 具有語(yǔ)言代碼 (ISO 639-1) 和字串值。

以下是建立控制器函數(shù):

import express from 'express'
import routeNames from '../config/countryRoutes.config'
import authJwt from '../middlewares/authJwt'
import * as countryController from '../controllers/countryController'

const routes = express.Router()

routes.route(routeNames.validate).post(authJwt.verifyToken, countryController.validate)
routes.route(routeNames.create).post(authJwt.verifyToken, countryController.create)
routes.route(routeNames.update).put(authJwt.verifyToken, countryController.update)
routes.route(routeNames.delete).delete(authJwt.verifyToken, countryController.deleteCountry)
routes.route(routeNames.getCountry).get(authJwt.verifyToken, countryController.getCountry)
routes.route(routeNames.getCountries).get(authJwt.verifyToken, countryController.getCountries)
routes.route(routeNames.getCountriesWithLocations).get(countryController.getCountriesWithLocations)
routes.route(routeNames.checkCountry).get(authJwt.verifyToken, countryController.checkCountry)
routes.route(routeNames.getCountryId).get(authJwt.verifyToken, countryController.getCountryId)

export default routes

在此函數(shù)中,我們檢索請(qǐng)求的正文,迭代正文中提供的值(每種語(yǔ)言一個(gè)值)並建立一個(gè) LocationValue。最後,我們根據(jù)建立的位置值建立國(guó)家/地區(qū)。

前端

前端是一個(gè)使用 Node.js、React、MUI 和 TypeScript 建立的 Web 應(yīng)用程式。在前端,客戶可以根據(jù)接送點(diǎn)和時(shí)間搜尋可用的汽車,選擇汽車並繼續(xù)結(jié)帳:

  • ./frontend/src/assets/ 資料夾包含 CSS 和圖片。
  • ./frontend/src/pages/ 資料夾包含 React 頁(yè)面。
  • ./frontend/src/components/ 資料夾包含 React 元件。
  • ./frontend/src/services/ 包含 api 客戶端服務(wù)。
  • ./frontend/src/App.tsx 是包含路由的主 React 應(yīng)用程式。
  • ./frontend/src/index.tsx 是前端的主要入口點(diǎn)。

TypeScript 類型定義在套件 ./packages/bookcars-types 中定義。

App.tsx 是主要的 React 應(yīng)用程式:

const routes = {
  validate: '/api/validate-country',
  create: '/api/create-country',
  update: '/api/update-country/:id',
  delete: '/api/delete-country/:id',
  getCountry: '/api/country/:id/:language',
  getCountries: '/api/countries/:page/:size/:language',
  getCountriesWithLocations: '/api/countries-with-locations/:language/:imageRequired/:minLocations',
  checkCountry: '/api/check-country/:id',
  getCountryId: '/api/country-id/:name/:language',
}

export default routes

我們使用 React 延遲載入來(lái)載入每個(gè)路由。

我們不會(huì)涵蓋前端的每一頁(yè),但如果您願(yuàn)意,您可以打開(kāi)原始程式碼並查看每一頁(yè)。

手機(jī)應(yīng)用程式

該平臺(tái)提供適用於 Android 和 iOS 的本機(jī)行動(dòng)應(yīng)用程式。這個(gè)行動(dòng)應(yīng)用程式是使用 React Native、Expo 和 TypeScript 建構(gòu)的。與前端一樣,行動(dòng)應(yīng)用程式允許客戶根據(jù)接送點(diǎn)和時(shí)間搜尋可用的汽車,選擇汽車並繼續(xù)結(jié)帳。

如果他的預(yù)訂從後端更新,客戶會(huì)收到推播通知。推播通知是使用 Node.js、Expo Server SDK 和 Firebase 建構(gòu)的。

  • ./mobile/assets/ 資料夾包含影像。
  • ./mobile/screens/ 資料夾包含主要的 React Native 螢?zāi)弧?
  • ./mobile/components/ 資料夾包含 React Native 元件。
  • ./mobile/services/ 包含 api 客戶端服務(wù)。
  • ./mobile/App.tsx 是主要的 React Native 應(yīng)用程式。

TypeScript 類型定義定義於:

  • ./mobile/types/index.d.ts
  • ./mobile/types/env.d.ts
  • ./mobile/miscellaneous/bookcarsTypes.ts

./mobile/types/ 載入到 ./mobile/tsconfig.json 中,如下所示:

import { Schema, model } from 'mongoose'
import * as env from '../config/env.config'

const countrySchema = new Schema<env.Country>(
  {
    values: {
      type: [Schema.Types.ObjectId],
      ref: 'LocationValue',
      required: [true, "can't be blank"],
      validate: (value: any): boolean => Array.isArray(value),
    },
  },
  {
    timestamps: true,
    strict: true,
    collection: 'Country',
  },
)

const Country = model<env.Country>('Country', countrySchema)

export default Country

App.tsx 是 React Native 應(yīng)用程式的主要入口點(diǎn):

導(dǎo)入'react-native-gesture-handler'
從 'react' 導(dǎo)入 React, { useCallback, useEffect, useRef, useState }
從 'react-native-root-siblings' 導(dǎo)入 { RootSiblingParent }
從'@react-navigation/native'導(dǎo)入{NavigationContainer,NavigationContainerRef}
從“expo-status-bar”導(dǎo)入 { StatusBar as ExpoStatusBar }
從 'react-native-safe-area-context' 導(dǎo)入 { SafeAreaProvider }
從 'react-native-paper' 導(dǎo)入 { Provider }
從“expo-splash-screen”導(dǎo)入 * as SplashScreen
導(dǎo)入 * 作為來(lái)自“expo-notifications”的通知
從 '@stripe/stripe-react-native' 導(dǎo)入 { StripeProvider }
從 './components/DrawerNavigator' 導(dǎo)入 DrawerNavigator
從 './common/helper' 導(dǎo)入 * 作為助手
從'./services/NotificationService'導(dǎo)入*作為NotificationService
從 './services/UserService' 導(dǎo)入 * 作為 UserService
從 './context/GlobalContext' 導(dǎo)入 { GlobalProvider }
從 './config/env.config' 導(dǎo)入 * 作為 env

通知.setNotificationHandler({
  handlerNotification: async() =>; ({
    應(yīng)該會(huì)顯示警報(bào):真,
    應(yīng)該播放聲音:真,
    應(yīng)該要設(shè)定徽章:真,
  }),
})

//
// 防止本機(jī)啟動(dòng)畫面在應(yīng)用程式元件宣告之前自動(dòng)隱藏
//
SplashScreen.preventAutoHideAsync()
  .then((結(jié)果) => console.log(`SplashScreen.preventAutoHideAsync() 成功:${result}`))
  .catch(console.warn) // 最好明確捕獲並檢查任何錯(cuò)誤

const App = () =>; {
  const [appIsReady, setAppIsReady] = useState(false)

  const responseListener = useRef<notifications.subscription>()
  const navigationRef = useRef<navigationcontainerref>>(null)

  useEffect(() => {
    const 暫存器 = async() => {
      const LoggedIn = 等待 UserService.loggedIn()
      如果(登入){
        const currentUser = 等待 UserService.getCurrentUser()
        if (目前使用者?._id) {
          等待 helper.registerPushToken(currentUser._id)
        } 別的 {
          helper.error()
        }
      }
    }

    //
    // 註冊(cè)推播通知令牌
    //
    登記()

    //
    // 每當(dāng)使用者點(diǎn)擊通知或與通知互動(dòng)時(shí)就會(huì)觸發(fā)此偵聽(tīng)器(當(dāng)應(yīng)用程式處?kù)肚芭_(tái)、背景或終止時(shí)有效)
    //
    responseListener.current = Notifications.addNotificationResponseReceivedListener(async (response) => {
      嘗試 {
        如果(navigationRef.current){
          const { 資料 } = 回應(yīng).通知.請(qǐng)求.內(nèi)容

          如果(資料.預(yù)訂){
            if (data.user && data.notification) {
              等待NotificationService.markAsRead(data.user, [data.notification])
            }
            navigationRef.current.navigate('預(yù)訂', { id: data.booking })
          } 別的 {
            navigationRef.current.navigate('通知', {})
          }
        }
      } 捕獲(錯(cuò)誤){
        helper.error(錯(cuò)誤,錯(cuò)誤)
      }
    })

    返回() => {
      Notifications.removeNotificationSubscription(responseListener.current!)
    }
  }, [])

  setTimeout(() => {
    設(shè)定應(yīng)用程式已就緒(true)
  }, 500)

  const onReady = useCallback(async () => {
    如果(應(yīng)用程式已就緒){
      //
      // 這告訴啟動(dòng)畫面立即隱藏!如果我們之後調(diào)用這個(gè)
      // `setAppIsReady`,那麼當(dāng)應(yīng)用程式運(yùn)行時(shí)我們可能會(huì)看到一個(gè)空白螢?zāi)?      // 載入其初始狀態(tài)並渲染其第一個(gè)像素。所以相反,
      // 一旦我們知道根視圖已經(jīng)隱藏了啟動(dòng)畫面
      // 執(zhí)行佈局。
      //
      等待 SplashScreen.hideAsync()
    }
  }, [應(yīng)用程式已就緒])

  如果(!appIsReady){
    傳回空值
  }

  返回 (
    
      
        
          <stripeproviderpublishablekey>;
            <rootsiblingparent>
              <navigationcontainer ref="{navigationRef}" onready="{onReady}">
                



<p>我們不會(huì)涵蓋行動(dòng)應(yīng)用程式的每個(gè)螢?zāi)?,但您可以根?jù)需要打開(kāi)原始程式碼並查看每個(gè)螢?zāi)弧?</p>

<h2>
  
  
  管理儀表板
</h2>

<p>管理儀表板是一個(gè)使用 Node.js、React、MUI 和 TypeScript 建立的 Web 應(yīng)用程式。管理員可以從後端建立和管理供應(yīng)商、汽車、位置、客戶和預(yù)訂。當(dāng)從後端創(chuàng)建新的供應(yīng)商時(shí),他們將收到一封電子郵件,提示他們建立一個(gè)帳戶,以便訪問(wèn)後端並管理他們的車隊(duì)和預(yù)訂。 </p>

<ul>
<li>./backend/assets/ 資料夾包含 CSS 和圖片。 </li>
<li>./backend/pages/ 資料夾包含 React 頁(yè)面。 </li>
<li>./backend/components/ 資料夾包含 React 元件。 </li>
<li>./backend/services/ 包含 api 客戶端服務(wù)。 </li>
<li>./backend/App.tsx 是包含路由的主要 React 應(yīng)用程式。 </li>
<li>./backend/index.tsx 是管理儀表板的主要入口點(diǎn)。 </li>
</ul>

<p>TypeScript 類型定義在套件 ./packages/bookcars-types 中定義。 </p>

<p>後端的 App.tsx 與前端的 App.tsx 遵循類似的邏輯。 </p>

<p>我們不會(huì)涵蓋管理儀表板的每一頁(yè),但您可以根據(jù)需要開(kāi)啟原始程式碼並查看每一頁(yè)。 </p>

<h2>
  
  
  興趣點(diǎn)
</h2>

<p>使用 React Native 和 Expo 建立行動(dòng)應(yīng)用程式非常簡(jiǎn)單。 Expo 讓使用 React Native 進(jìn)行行動(dòng)開(kāi)發(fā)變得非常簡(jiǎn)單。 </p>

<p>後端、前端和行動(dòng)裝置開(kāi)發(fā)使用同一種語(yǔ)言(TypeScript)非常方便。 </p>

<p>TypeScript 是一門非常有趣的語(yǔ)言,並且有很多優(yōu)點(diǎn)。透過(guò)向 JavaScript 添加靜態(tài)類型,我們可以避免許多錯(cuò)誤並產(chǎn)生高品質(zhì)、可擴(kuò)展、更具可讀性和可維護(hù)性的程式碼,並且易於調(diào)試和測(cè)試。 </p>

<p>就是這樣!我希望您喜歡閱讀這篇文章。 </p>
<h2>
  
  
  資源
</h2>

<ol>
<li>概述</li>
<li>建築</li>
<li>安裝(自架)</li>
<li>安裝(VPS)</li>
<li>
安裝(Docker)

<ol>
<li>Docker 映像</li>
<li>SSL</li>
</ol>


</li>

<li>設(shè)定條紋</li>

<li>建立行動(dòng)應(yīng)用程式</li>

<li>

演示資料庫(kù)

<ol>
<li>Windows、Linux 和 macOS</li>
<li>碼頭工人</li>
</ol>


</li>

<li>從源頭運(yùn)行</li>

<li>

運(yùn)行行動(dòng)應(yīng)用程式

<ol>
<li>先決條件</li>
<li>使用說(shuō)明</li>
<li>推播通知</li>
</ol>


</li>

<li>更改貨幣</li>

<li>新增語(yǔ)言</li>

<li>單元測(cè)試和覆蓋率</li>

<li>日誌</li>

</ol>


          

            
        </navigationcontainer></rootsiblingparent></stripeproviderpublishablekey></navigationcontainerref></notifications.subscription>

以上是從零到店面:我建立汽車租賃網(wǎng)站和行動(dòng)應(yīng)用程式的旅程的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開(kāi)發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

熱門話題

Laravel 教程
1600
29
PHP教程
1502
276
如何在node.js中提出HTTP請(qǐng)求? 如何在node.js中提出HTTP請(qǐng)求? Jul 13, 2025 am 02:18 AM

在Node.js中發(fā)起HTTP請(qǐng)求有三種常用方式:使用內(nèi)置模塊、axios和node-fetch。 1.使用內(nèi)置的http/https模塊無(wú)需依賴,適合基礎(chǔ)場(chǎng)景,但需手動(dòng)處理數(shù)據(jù)拼接和錯(cuò)誤監(jiān)聽(tīng),例如用https.get()獲取數(shù)據(jù)或通過(guò).write()發(fā)送POST請(qǐng)求;2.axios是基於Promise的第三方庫(kù),語(yǔ)法簡(jiǎn)潔且功能強(qiáng)大,支持async/await、自動(dòng)JSON轉(zhuǎn)換、攔截器等,推薦用於簡(jiǎn)化異步請(qǐng)求操作;3.node-fetch提供類似瀏覽器fetch的風(fēng)格,基於Promise且語(yǔ)法簡(jiǎn)單

JavaScript數(shù)據(jù)類型:原始與參考 JavaScript數(shù)據(jù)類型:原始與參考 Jul 13, 2025 am 02:43 AM

JavaScript的數(shù)據(jù)類型分為原始類型和引用類型。原始類型包括string、number、boolean、null、undefined和symbol,其值不可變且賦值時(shí)復(fù)制副本,因此互不影響;引用類型如對(duì)象、數(shù)組和函數(shù)存儲(chǔ)的是內(nèi)存地址,指向同一對(duì)象的變量會(huì)相互影響。判斷類型可用typeof和instanceof,但需注意typeofnull的歷史問(wèn)題。理解這兩類差異有助於編寫更穩(wěn)定可靠的代碼。

JavaScript時(shí)間對(duì)象,某人構(gòu)建了一個(gè)eactexe,在Google Chrome上更快的網(wǎng)站等等 JavaScript時(shí)間對(duì)象,某人構(gòu)建了一個(gè)eactexe,在Google Chrome上更快的網(wǎng)站等等 Jul 08, 2025 pm 02:27 PM

JavaScript開(kāi)發(fā)者們,大家好!歡迎閱讀本週的JavaScript新聞!本週我們將重點(diǎn)關(guān)注:Oracle與Deno的商標(biāo)糾紛、新的JavaScript時(shí)間對(duì)象獲得瀏覽器支持、GoogleChrome的更新以及一些強(qiáng)大的開(kāi)發(fā)者工具。讓我們開(kāi)始吧! Oracle與Deno的商標(biāo)之爭(zhēng)Oracle試圖註冊(cè)“JavaScript”商標(biāo)的舉動(dòng)引發(fā)爭(zhēng)議。 Node.js和Deno的創(chuàng)建者RyanDahl已提交請(qǐng)願(yuàn)書,要求取消該商標(biāo),他認(rèn)為JavaScript是一個(gè)開(kāi)放標(biāo)準(zhǔn),不應(yīng)由Oracle

處理諾言:鏈接,錯(cuò)誤處理和承諾在JavaScript中 處理諾言:鏈接,錯(cuò)誤處理和承諾在JavaScript中 Jul 08, 2025 am 02:40 AM

Promise是JavaScript中處理異步操作的核心機(jī)制,理解鍊式調(diào)用、錯(cuò)誤處理和組合器是掌握其應(yīng)用的關(guān)鍵。 1.鍊式調(diào)用通過(guò).then()返回新Promise實(shí)現(xiàn)異步流程串聯(lián),每個(gè).then()接收上一步結(jié)果並可返回值或Promise;2.錯(cuò)誤處理應(yīng)統(tǒng)一使用.catch()捕獲異常,避免靜默失敗,並可在catch中返回默認(rèn)值繼續(xù)流程;3.組合器如Promise.all()(全成功才成功)、Promise.race()(首個(gè)完成即返回)和Promise.allSettled()(等待所有完成)

什麼是緩存API?如何與服務(wù)人員使用? 什麼是緩存API?如何與服務(wù)人員使用? Jul 08, 2025 am 02:43 AM

CacheAPI是瀏覽器提供的一種緩存網(wǎng)絡(luò)請(qǐng)求的工具,常與ServiceWorker配合使用,以提升網(wǎng)站性能和離線體驗(yàn)。 1.它允許開(kāi)發(fā)者手動(dòng)存儲(chǔ)如腳本、樣式表、圖片等資源;2.可根據(jù)請(qǐng)求匹配緩存響應(yīng);3.支持刪除特定緩存或清空整個(gè)緩存;4.通過(guò)ServiceWorker監(jiān)聽(tīng)fetch事件實(shí)現(xiàn)緩存優(yōu)先或網(wǎng)絡(luò)優(yōu)先等策略;5.常用於離線支持、加快重複訪問(wèn)速度、預(yù)加載關(guān)鍵資源及後臺(tái)更新內(nèi)容;6.使用時(shí)需注意緩存版本控制、存儲(chǔ)限制及與HTTP緩存機(jī)制的區(qū)別。

JS綜述:深入研究JavaScript事件循環(huán) JS綜述:深入研究JavaScript事件循環(huán) Jul 08, 2025 am 02:24 AM

JavaScript的事件循環(huán)通過(guò)協(xié)調(diào)調(diào)用棧、WebAPI和任務(wù)隊(duì)列來(lái)管理異步操作。 1.調(diào)用棧執(zhí)行同步代碼,遇到異步任務(wù)時(shí)交由WebAPI處理;2.WebAPI在後臺(tái)完成任務(wù)後將回調(diào)放入相應(yīng)的隊(duì)列(宏任務(wù)或微任務(wù));3.事件循環(huán)檢查調(diào)用棧是否為空,若為空則從隊(duì)列中取出回調(diào)推入調(diào)用棧執(zhí)行;4.微任務(wù)(如Promise.then)優(yōu)先於宏任務(wù)(如setTimeout)執(zhí)行;5.理解事件循環(huán)有助於避免阻塞主線程並優(yōu)化代碼執(zhí)行順序。

了解事件在JavaScript DOM事件中冒泡和捕獲 了解事件在JavaScript DOM事件中冒泡和捕獲 Jul 08, 2025 am 02:36 AM

事件冒泡是從目標(biāo)元素向外傳播到祖先節(jié)點(diǎn),事件捕獲則是從外層向內(nèi)傳播到目標(biāo)元素。 1.事件冒泡:點(diǎn)擊子元素後,事件依次向上觸發(fā)父級(jí)元素的監(jiān)聽(tīng)器,例如點(diǎn)擊按鈕後先輸出Childclicked,再輸出Parentclicked。 2.事件捕獲:設(shè)置第三個(gè)參數(shù)為true,使監(jiān)聽(tīng)器在捕獲階段執(zhí)行,如點(diǎn)擊按鈕前先觸發(fā)父元素的捕獲監(jiān)聽(tīng)器。 3.實(shí)際用途包括統(tǒng)一管理子元素事件、攔截預(yù)處理和性能優(yōu)化。 4.DOM事件流分為捕獲、目標(biāo)和冒泡三個(gè)階段,默認(rèn)監(jiān)聽(tīng)器在冒泡階段執(zhí)行。

超越地圖和過(guò)濾器的高階功能的JS綜述 超越地圖和過(guò)濾器的高階功能的JS綜述 Jul 10, 2025 am 11:41 AM

JavaScript數(shù)組中,除了map和filter,還有其他強(qiáng)大且不常用的方法。 1.reduce不僅能求和,還可計(jì)數(shù)、分組、展平數(shù)組、構(gòu)建新結(jié)構(gòu);2.find和findIndex用於查找單個(gè)元素或索引;3.some和every用於判斷是否存在或全部滿足條件;4.sort可排序但會(huì)改變?cè)瓟?shù)組;5.使用時(shí)注意複製數(shù)組避免副作用。這些方法使代碼更簡(jiǎn)潔高效。

See all articles