# @blueking/login-modal

> window.open 小窗登录统一方法

Latest version **1.0.6** (published 2025-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @blueking/login-modal
pnpm add @blueking/login-modal
yarn add @blueking/login-modal
bun add @blueking/login-modal
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2025-02-19 |
| First published | 2024-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | bkfe |
| Maintainers | blueking |

## Links

- npm: https://www.npmjs.com/package/@blueking/login-modal
- npm.io page: https://npm.io/package/@blueking/login-modal

## Recent versions

- 1.0.6 (latest) — 2025-02-19
- 1.0.5 — 2024-05-14
- 1.0.4 — 2024-05-12
- 1.0.3 — 2024-05-10
- 1.0.2 — 2024-04-23
- 1.0.1 — 2024-04-09
- 1.0.0 — 2024-04-09

## README

# login-modal

window.open 小窗登录统一方法

# Install

```bash
npm install @blueking/login-modal
```

# Usage

```js
import { showLoginModal } from '@blueking/login-modal'

// ...
if (status === 401) {
  // 登录成功之后的回调地址，用于执行关闭登录窗口或刷新父窗口页面等动作
  const successUrl = `${window.location.origin}/static/login_success.html`

  // 系统的登录页地址
  const siteLoginUrl = window.Site.login
  if (!siteLoginUrl) {
    console.error('Login URL not configured!')
    return
  }

  // 处理登录地址为登录小窗需要的格式，主要是设置c_url参数
  const loginURL = new URL(siteLoginUrl)
  loginURL.searchParams.set('c_url', successUrl)
  const pathname = loginURL.pathname.endsWith('/') ? loginURL.pathname : `${loginURL.pathname}/`
  const loginUrl = `${loginURL.origin}${pathname}plain/${loginURL.search}`

  // 传入最终的登录地址，弹出登录窗口，更多选项参考 Options
  showLoginModal({ loginUrl })
}
```

# Options
`showLoginModal(options)` 支持传入的配置
```js
const {
  loginUrl,
  width = 700,
  height = 510,
  maskColor = 'rgba(0, 0, 0, .6)',
  maskZIndex = 99999,
  onClosed = null // 窗口关闭回调
} = options
```
返回值：成功时登录窗口的 `WindowProxy`，失败时为 `null`

---
_Source: https://npm.io/package/@blueking/login-modal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
