WeUI+ Documentation

repository·master·Indexed 23 days ago

https://github.com/logoove/weui

A mobile-focused UI library for HTML5 and WeChat Official Account applications, inspired by Zepto and the original WeUI. It provides nearly 100 components and plugins, including support for image galleries, pull-to-refresh, and location selection. The library includes a Golang-based backend (built with GoFrame and SQLite) providing RESTful APIs for versioning, sponsorship management, page view tracking (PV/UV), captcha generation, and city search.

Tokens
1.5K
Snippets
4
Records
11
Agent score
83%

What's inside WeUI+

  1. Overview of WeUI+

    master

    WeUI+ is a comprehensive Mobile UI library designed for developing HTML5 and WeChat Official Account (公众号) applications. It is built upon Zepto 1.2 and WeUI 1.13, offering nearly 100 components and plugins to provide a highly complete mobile user interface experience.

    Key features include:

    • Extensive component library (nearly 100 plugins/components).
    • Support for mobile-specific interactions (e.g., shake, pull-to-refresh, image galleries).
    • Built-in backend services (recently migrated from PHP to Golang).
    • Cross-platform compatibility for mobile web environments.
  2. Run the WeUI+ backend service

    master

    The latest versions of WeUI+ use a Golang-based backend. You can run the included server by executing the compiled binary. Once running, access the service via your browser at:

    http://127.0.0.1:8080

    http://127.0.0.1:8080
  3. Compile the WeUI+ backend

    master

    The backend can be compiled using Go. To ensure the binary is as small as possible, use the -ldflags "-s -w" flags. You can further compress the resulting binary using the upx tool.

    Important: When compiling (for example, in WSL2), ensure that CGO is disabled, as enabling it may result in non-functional binaries.

    # Windows
    go build -ldflags "-s -w" -o win-weui-amd64.exe
    
    # Linux
    go build -ldflags "-s -w" -o linux-weui-amd64
  4. Compile the Golang backend for cross-platform use

    master

    The backend is designed to be compiled without cgo, allowing for easy cross-platform compilation. It requires goframe2 or higher and sqlite.

    When compiling, ensure you follow the requirements for the target system. The project provides pre-compiled binaries for Windows 10 and Linux.

  5. How to run the WeUI+ Server

    master

    The WeUI+ server is a Go application built using the GoFrame framework. By default, it runs on port 8885 and serves static files from the ./weui directory.

    Default Access

    • Local Access: http://127.0.0.1:8885
    • Static Files: Accessible via the /weui prefix (e.g., http://127.0.0.1:8885/weui/index.html).

    Requirements

    • A SQLite database file located at weui/db.db.
    • A weui/ver file containing two lines: the version string and the date.
    • A weui/README.md file for the /v1/md endpoint.
  6. Use functions from js/fn.js

    master

    The project provides a utility library located at js/fn.js. In newer versions (v6.03+), these functions are exported using ES modules. To use specific functions, you must import them explicitly to avoid bloating your bundle.

    Example of importing specific utilities:

    import { md5, dump } from 'js/fn.js';
    import {md5,dump} from 'js/fn.js'
  7. Reference: Recent feature additions and API changes

    master

    Below is a summary of notable recent functional additions and API changes documented in the changelog:

    • v6.11.01: Backend framework upgraded; API paths unified to /v1/XX.
    • v6.092: Added $.prompts() for text area popup prompts (used for comments).
    • v6.091: Added gallery() function for image previewing (viewing large images, deleting images, etc.).
    • v6.09: Added number flipping/formatting functions in fn.js (e.g., converting large numbers to '10w+', '1.00k', etc.).
    • v6.08: Added four-level location selection (Province, City, County, Township/Street).
    • v6.04: Backend rewritten using goframe (previously gin) with sqlite3 (no cgo required).
    • v6.03: fn.js rewritten to use export. Added JS table sorting supporting string, int, float, and date types.
    • v6.01: Added /pvuv interface for site traffic statistics (Type 1 for UV, Type 0 for PV).
  8. WeUI+ Server API Reference

    master

    The WeUI+ server provides a RESTful API under the /v1 prefix to support various frontend functionalities including version checking, sponsorship management, statistics, and location services. All endpoints in the /v1 group have CORS enabled by default.

    Versioning and Metadata

    • POST /v1/ver: Retrieves the current version and release date from the server's local files.
    • POST /v1/md: Returns the raw content of the weui/README.md file.

    Sponsorship Management

    • GET /v1/zlist: Retrieves a paginated list of sponsors. Requires page and pagesize query parameters.
    • GET /v1/zlist1: Retrieves a list of sponsors using a start offset and pagesize.
    • POST /v1/login: An administrative endpoint. If the correct password (123) is provided via the pwd parameter, it returns a HTML snippet for the sponsorship input form.
    • POST /v1/savedata: Saves a new sponsorship entry. Requires zid (sponsor name), money (amount), and say (message) parameters.
  9. WeUI+ Statistics and Captcha API

    master

    Page View Tracking

    • GET /v1/pvuv: Tracks page views (PV/UV).
      • Parameters: types (string) and md5 (string, required).
      • Behavior: If the md5 hash for the page/type combination doesn't exist in the stat table, it creates a new record. Otherwise, it increments the num field.

    Security and Utilities

    • GET /v1/code: Generates a base64-encoded captcha image using base64Captcha. Returns a JSON object with the img string.
    • POST /v1/upimg: Converts a base64 image string into a physical file.
      • Parameter: imgbase64 (the full data URI string).
      • Behavior: Saves the image to ./weui/php/image using a SHA1 hash of the data as the filename and returns the file path.
    • GET /v1/getimg: Generates a dynamic solid-color PNG image.
      • Parameter: c (format: widthxheight, e.g., 100x100).
  10. WeUI+ Location and City Search API

    master

    These endpoints provide lookup services for city and province data stored in the database.

    • POST /v1/getcity: Look up a city name by its code.
      • Parameter: code (string).
    • POST /v1/getpy: Search for cities using Pinyin.
      • Parameter: py (string).
    • POST /v1/getso: Search for cities using a keyword match on the name.
      • Parameter: kw (string).