Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74f8fa5f4e |
@@ -5,16 +5,14 @@ description: "Use when the user needs to run GitNexus CLI commands like analyze/
|
|||||||
|
|
||||||
# GitNexus CLI Commands
|
# GitNexus CLI Commands
|
||||||
|
|
||||||
Commands below use `node .gitnexus/run.cjs <command>` — the project-local runner `gitnexus analyze` drops next to the index. It auto-selects an available runner at call time (global `gitnexus`, else `pnpm dlx`, else `npx`), so no package-manager assumption and no global install is required.
|
All commands work via `npx` — no global install required.
|
||||||
|
|
||||||
> **Not analyzed yet, or `node .gitnexus/run.cjs` reports `Cannot find module`** (the gitignored runner is absent — e.g. a fresh clone or `git clean`)? (Re)generate it with `npx gitnexus analyze` from the project root. On **npm 11.x**, if `npx` crashes during install (`node.target is null`), install once with `npm i -g gitnexus` (then `gitnexus analyze`) or use `pnpm --allow-build=@ladybugdb/core --allow-build=gitnexus --allow-build=tree-sitter dlx gitnexus@latest analyze`. See [#1939](https://github.com/abhigyanpatwari/GitNexus/issues/1939).
|
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
### analyze — Build or refresh the index
|
### analyze — Build or refresh the index
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node .gitnexus/run.cjs analyze
|
npx gitnexus analyze
|
||||||
```
|
```
|
||||||
|
|
||||||
Run from the project root. This parses all source files, builds the knowledge graph, writes it to `.gitnexus/`, and generates CLAUDE.md / AGENTS.md context files.
|
Run from the project root. This parses all source files, builds the knowledge graph, writes it to `.gitnexus/`, and generates CLAUDE.md / AGENTS.md context files.
|
||||||
@@ -30,7 +28,7 @@ Run from the project root. This parses all source files, builds the knowledge gr
|
|||||||
### status — Check index freshness
|
### status — Check index freshness
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node .gitnexus/run.cjs status
|
npx gitnexus status
|
||||||
```
|
```
|
||||||
|
|
||||||
Shows whether the current repo has a GitNexus index, when it was last updated, and symbol/relationship counts. Use this to check if re-indexing is needed.
|
Shows whether the current repo has a GitNexus index, when it was last updated, and symbol/relationship counts. Use this to check if re-indexing is needed.
|
||||||
@@ -38,7 +36,7 @@ Shows whether the current repo has a GitNexus index, when it was last updated, a
|
|||||||
### clean — Delete the index
|
### clean — Delete the index
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node .gitnexus/run.cjs clean
|
npx gitnexus clean
|
||||||
```
|
```
|
||||||
|
|
||||||
Deletes the `.gitnexus/` directory and unregisters the repo from the global registry. Use before re-indexing if the index is corrupt or after removing GitNexus from a project.
|
Deletes the `.gitnexus/` directory and unregisters the repo from the global registry. Use before re-indexing if the index is corrupt or after removing GitNexus from a project.
|
||||||
@@ -51,7 +49,7 @@ Deletes the `.gitnexus/` directory and unregisters the repo from the global regi
|
|||||||
### wiki — Generate documentation from the graph
|
### wiki — Generate documentation from the graph
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node .gitnexus/run.cjs wiki
|
npx gitnexus wiki
|
||||||
```
|
```
|
||||||
|
|
||||||
Generates repository documentation from the knowledge graph using an LLM. Requires an API key (saved to `~/.gitnexus/config.json` on first use).
|
Generates repository documentation from the knowledge graph using an LLM. Requires an API key (saved to `~/.gitnexus/config.json` on first use).
|
||||||
@@ -68,7 +66,7 @@ Generates repository documentation from the knowledge graph using an LLM. Requir
|
|||||||
### list — Show all indexed repos
|
### list — Show all indexed repos
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node .gitnexus/run.cjs list
|
npx gitnexus list
|
||||||
```
|
```
|
||||||
|
|
||||||
Lists all repositories registered in `~/.gitnexus/registry.json`. The MCP `list_repos` tool provides the same information.
|
Lists all repositories registered in `~/.gitnexus/registry.json`. The MCP `list_repos` tool provides the same information.
|
||||||
|
|||||||
@@ -16,23 +16,23 @@ description: "Use when the user is debugging a bug, tracing an error, or asking
|
|||||||
## Workflow
|
## Workflow
|
||||||
|
|
||||||
```
|
```
|
||||||
1. query({query: "<error or symptom>"}) → Find related execution flows
|
1. gitnexus_query({query: "<error or symptom>"}) → Find related execution flows
|
||||||
2. context({name: "<suspect>"}) → See callers/callees/processes
|
2. gitnexus_context({name: "<suspect>"}) → See callers/callees/processes
|
||||||
3. READ gitnexus://repo/{name}/process/{name} → Trace execution flow
|
3. READ gitnexus://repo/{name}/process/{name} → Trace execution flow
|
||||||
4. cypher({query: "MATCH path..."}) → Custom traces if needed
|
4. gitnexus_cypher({query: "MATCH path..."}) → Custom traces if needed
|
||||||
```
|
```
|
||||||
|
|
||||||
> If "Index is stale" → run `node .gitnexus/run.cjs analyze` in terminal.
|
> If "Index is stale" → run `npx gitnexus analyze` in terminal.
|
||||||
|
|
||||||
## Checklist
|
## Checklist
|
||||||
|
|
||||||
```
|
```
|
||||||
- [ ] Understand the symptom (error message, unexpected behavior)
|
- [ ] Understand the symptom (error message, unexpected behavior)
|
||||||
- [ ] query for error text or related code
|
- [ ] gitnexus_query for error text or related code
|
||||||
- [ ] Identify the suspect function from returned processes
|
- [ ] Identify the suspect function from returned processes
|
||||||
- [ ] context to see callers and callees
|
- [ ] gitnexus_context to see callers and callees
|
||||||
- [ ] Trace execution flow via process resource if applicable
|
- [ ] Trace execution flow via process resource if applicable
|
||||||
- [ ] cypher for custom call chain traces if needed
|
- [ ] gitnexus_cypher for custom call chain traces if needed
|
||||||
- [ ] Read source files to confirm root cause
|
- [ ] Read source files to confirm root cause
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ description: "Use when the user is debugging a bug, tracing an error, or asking
|
|||||||
|
|
||||||
| Symptom | GitNexus Approach |
|
| Symptom | GitNexus Approach |
|
||||||
| -------------------- | ---------------------------------------------------------- |
|
| -------------------- | ---------------------------------------------------------- |
|
||||||
| Error message | `query` for error text → `context` on throw sites |
|
| Error message | `gitnexus_query` for error text → `context` on throw sites |
|
||||||
| Wrong return value | `context` on the function → trace callees for data flow |
|
| Wrong return value | `context` on the function → trace callees for data flow |
|
||||||
| Intermittent failure | `context` → look for external calls, async deps |
|
| Intermittent failure | `context` → look for external calls, async deps |
|
||||||
| Performance issue | `context` → find symbols with many callers (hot paths) |
|
| Performance issue | `context` → find symbols with many callers (hot paths) |
|
||||||
@@ -48,24 +48,24 @@ description: "Use when the user is debugging a bug, tracing an error, or asking
|
|||||||
|
|
||||||
## Tools
|
## Tools
|
||||||
|
|
||||||
**query** — find code related to error:
|
**gitnexus_query** — find code related to error:
|
||||||
|
|
||||||
```
|
```
|
||||||
query({query: "payment validation error"})
|
gitnexus_query({query: "payment validation error"})
|
||||||
→ Processes: CheckoutFlow, ErrorHandling
|
→ Processes: CheckoutFlow, ErrorHandling
|
||||||
→ Symbols: validatePayment, handlePaymentError, PaymentException
|
→ Symbols: validatePayment, handlePaymentError, PaymentException
|
||||||
```
|
```
|
||||||
|
|
||||||
**context** — full context for a suspect:
|
**gitnexus_context** — full context for a suspect:
|
||||||
|
|
||||||
```
|
```
|
||||||
context({name: "validatePayment"})
|
gitnexus_context({name: "validatePayment"})
|
||||||
→ Incoming calls: processCheckout, webhookHandler
|
→ Incoming calls: processCheckout, webhookHandler
|
||||||
→ Outgoing calls: verifyCard, fetchRates (external API!)
|
→ Outgoing calls: verifyCard, fetchRates (external API!)
|
||||||
→ Processes: CheckoutFlow (step 3/7)
|
→ Processes: CheckoutFlow (step 3/7)
|
||||||
```
|
```
|
||||||
|
|
||||||
**cypher** — custom call chain traces:
|
**gitnexus_cypher** — custom call chain traces:
|
||||||
|
|
||||||
```cypher
|
```cypher
|
||||||
MATCH path = (a)-[:CodeRelation {type: 'CALLS'}*1..2]->(b:Function {name: "validatePayment"})
|
MATCH path = (a)-[:CodeRelation {type: 'CALLS'}*1..2]->(b:Function {name: "validatePayment"})
|
||||||
@@ -75,11 +75,11 @@ RETURN [n IN nodes(path) | n.name] AS chain
|
|||||||
## Example: "Payment endpoint returns 500 intermittently"
|
## Example: "Payment endpoint returns 500 intermittently"
|
||||||
|
|
||||||
```
|
```
|
||||||
1. query({query: "payment error handling"})
|
1. gitnexus_query({query: "payment error handling"})
|
||||||
→ Processes: CheckoutFlow, ErrorHandling
|
→ Processes: CheckoutFlow, ErrorHandling
|
||||||
→ Symbols: validatePayment, handlePaymentError
|
→ Symbols: validatePayment, handlePaymentError
|
||||||
|
|
||||||
2. context({name: "validatePayment"})
|
2. gitnexus_context({name: "validatePayment"})
|
||||||
→ Outgoing calls: verifyCard, fetchRates (external API!)
|
→ Outgoing calls: verifyCard, fetchRates (external API!)
|
||||||
|
|
||||||
3. READ gitnexus://repo/my-app/process/CheckoutFlow
|
3. READ gitnexus://repo/my-app/process/CheckoutFlow
|
||||||
|
|||||||
@@ -18,20 +18,20 @@ description: "Use when the user asks how code works, wants to understand archite
|
|||||||
```
|
```
|
||||||
1. READ gitnexus://repos → Discover indexed repos
|
1. READ gitnexus://repos → Discover indexed repos
|
||||||
2. READ gitnexus://repo/{name}/context → Codebase overview, check staleness
|
2. READ gitnexus://repo/{name}/context → Codebase overview, check staleness
|
||||||
3. query({query: "<what you want to understand>"}) → Find related execution flows
|
3. gitnexus_query({query: "<what you want to understand>"}) → Find related execution flows
|
||||||
4. context({name: "<symbol>"}) → Deep dive on specific symbol
|
4. gitnexus_context({name: "<symbol>"}) → Deep dive on specific symbol
|
||||||
5. READ gitnexus://repo/{name}/process/{name} → Trace full execution flow
|
5. READ gitnexus://repo/{name}/process/{name} → Trace full execution flow
|
||||||
```
|
```
|
||||||
|
|
||||||
> If step 2 says "Index is stale" → run `node .gitnexus/run.cjs analyze` in terminal.
|
> If step 2 says "Index is stale" → run `npx gitnexus analyze` in terminal.
|
||||||
|
|
||||||
## Checklist
|
## Checklist
|
||||||
|
|
||||||
```
|
```
|
||||||
- [ ] READ gitnexus://repo/{name}/context
|
- [ ] READ gitnexus://repo/{name}/context
|
||||||
- [ ] query for the concept you want to understand
|
- [ ] gitnexus_query for the concept you want to understand
|
||||||
- [ ] Review returned processes (execution flows)
|
- [ ] Review returned processes (execution flows)
|
||||||
- [ ] context on key symbols for callers/callees
|
- [ ] gitnexus_context on key symbols for callers/callees
|
||||||
- [ ] READ process resource for full execution traces
|
- [ ] READ process resource for full execution traces
|
||||||
- [ ] Read source files for implementation details
|
- [ ] Read source files for implementation details
|
||||||
```
|
```
|
||||||
@@ -47,18 +47,18 @@ description: "Use when the user asks how code works, wants to understand archite
|
|||||||
|
|
||||||
## Tools
|
## Tools
|
||||||
|
|
||||||
**query** — find execution flows related to a concept:
|
**gitnexus_query** — find execution flows related to a concept:
|
||||||
|
|
||||||
```
|
```
|
||||||
query({query: "payment processing"})
|
gitnexus_query({query: "payment processing"})
|
||||||
→ Processes: CheckoutFlow, RefundFlow, WebhookHandler
|
→ Processes: CheckoutFlow, RefundFlow, WebhookHandler
|
||||||
→ Symbols grouped by flow with file locations
|
→ Symbols grouped by flow with file locations
|
||||||
```
|
```
|
||||||
|
|
||||||
**context** — 360-degree view of a symbol:
|
**gitnexus_context** — 360-degree view of a symbol:
|
||||||
|
|
||||||
```
|
```
|
||||||
context({name: "validateUser"})
|
gitnexus_context({name: "validateUser"})
|
||||||
→ Incoming calls: loginHandler, apiMiddleware
|
→ Incoming calls: loginHandler, apiMiddleware
|
||||||
→ Outgoing calls: checkToken, getUserById
|
→ Outgoing calls: checkToken, getUserById
|
||||||
→ Processes: LoginFlow (step 2/5), TokenRefresh (step 1/3)
|
→ Processes: LoginFlow (step 2/5), TokenRefresh (step 1/3)
|
||||||
@@ -68,10 +68,10 @@ context({name: "validateUser"})
|
|||||||
|
|
||||||
```
|
```
|
||||||
1. READ gitnexus://repo/my-app/context → 918 symbols, 45 processes
|
1. READ gitnexus://repo/my-app/context → 918 symbols, 45 processes
|
||||||
2. query({query: "payment processing"})
|
2. gitnexus_query({query: "payment processing"})
|
||||||
→ CheckoutFlow: processPayment → validateCard → chargeStripe
|
→ CheckoutFlow: processPayment → validateCard → chargeStripe
|
||||||
→ RefundFlow: initiateRefund → calculateRefund → processRefund
|
→ RefundFlow: initiateRefund → calculateRefund → processRefund
|
||||||
3. context({name: "processPayment"})
|
3. gitnexus_context({name: "processPayment"})
|
||||||
→ Incoming: checkoutHandler, webhookHandler
|
→ Incoming: checkoutHandler, webhookHandler
|
||||||
→ Outgoing: validateCard, chargeStripe, saveTransaction
|
→ Outgoing: validateCard, chargeStripe, saveTransaction
|
||||||
4. Read src/payments/processor.ts for implementation details
|
4. Read src/payments/processor.ts for implementation details
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ For any task involving code understanding, debugging, impact analysis, or refact
|
|||||||
2. **Match your task to a skill below** and **read that skill file**
|
2. **Match your task to a skill below** and **read that skill file**
|
||||||
3. **Follow the skill's workflow and checklist**
|
3. **Follow the skill's workflow and checklist**
|
||||||
|
|
||||||
> If step 1 warns the index is stale, run `node .gitnexus/run.cjs analyze` in the terminal first.
|
> If step 1 warns the index is stale, run `npx gitnexus analyze` in the terminal first.
|
||||||
|
|
||||||
## Skills
|
## Skills
|
||||||
|
|
||||||
@@ -38,38 +38,7 @@ For any task involving code understanding, debugging, impact analysis, or refact
|
|||||||
| `detect_changes` | Git-diff impact — what do your current changes affect |
|
| `detect_changes` | Git-diff impact — what do your current changes affect |
|
||||||
| `rename` | Multi-file coordinated rename with confidence-tagged edits |
|
| `rename` | Multi-file coordinated rename with confidence-tagged edits |
|
||||||
| `cypher` | Raw graph queries (read `gitnexus://repo/{name}/schema` first) |
|
| `cypher` | Raw graph queries (read `gitnexus://repo/{name}/schema` first) |
|
||||||
| `list_repos` | Discover indexed repos (paginated — `limit`/`offset`) |
|
| `list_repos` | Discover indexed repos |
|
||||||
|
|
||||||
### Paginating `list_repos`
|
|
||||||
|
|
||||||
`list_repos` is paginated so a large registry is not truncated by MCP/LLM token limits. It takes optional `limit` (default **50**, max **200**) and `offset`, and returns:
|
|
||||||
|
|
||||||
```jsonc
|
|
||||||
{
|
|
||||||
"repositories": [
|
|
||||||
{ "name": "...", "path": "...", "indexedAt": "...", "lastCommit": "...", "stats": { } }
|
|
||||||
],
|
|
||||||
"pagination": {
|
|
||||||
"total": 437,
|
|
||||||
"limit": 50,
|
|
||||||
"offset": 0,
|
|
||||||
"returned": 50,
|
|
||||||
"hasMore": true,
|
|
||||||
"nextOffset": 50
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To enumerate **every** repository, keep calling with `offset` set to `pagination.nextOffset` until `hasMore` is `false`:
|
|
||||||
|
|
||||||
```text
|
|
||||||
list_repos {} → repos 1–50, nextOffset 50, hasMore true
|
|
||||||
list_repos { offset: 50 } → repos 51–100, nextOffset 100, hasMore true
|
|
||||||
…
|
|
||||||
list_repos { offset: 400 } → repos 401–437, hasMore false (done)
|
|
||||||
```
|
|
||||||
|
|
||||||
Notes: `offset` ≥ `total` returns an empty page (with `total` still reported). Out-of-range or malformed `limit`/`offset` (non-integer, `limit` outside `[1, 200]`, `offset < 0`) are rejected with a clear error — `limit` above the max is rejected, not silently capped. The order is deterministic (lower-cased name, then path), so paging never skips or duplicates an entry while the registry is unchanged.
|
|
||||||
|
|
||||||
## Resources Reference
|
## Resources Reference
|
||||||
|
|
||||||
|
|||||||
@@ -17,22 +17,22 @@ description: "Use when the user wants to know what will break if they change som
|
|||||||
## Workflow
|
## Workflow
|
||||||
|
|
||||||
```
|
```
|
||||||
1. impact({target: "X", direction: "upstream"}) → What depends on this
|
1. gitnexus_impact({target: "X", direction: "upstream"}) → What depends on this
|
||||||
2. READ gitnexus://repo/{name}/processes → Check affected execution flows
|
2. READ gitnexus://repo/{name}/processes → Check affected execution flows
|
||||||
3. detect_changes() → Map current git changes to affected flows
|
3. gitnexus_detect_changes() → Map current git changes to affected flows
|
||||||
4. Assess risk and report to user
|
4. Assess risk and report to user
|
||||||
```
|
```
|
||||||
|
|
||||||
> If "Index is stale" → run `node .gitnexus/run.cjs analyze` in terminal.
|
> If "Index is stale" → run `npx gitnexus analyze` in terminal.
|
||||||
|
|
||||||
## Checklist
|
## Checklist
|
||||||
|
|
||||||
```
|
```
|
||||||
- [ ] impact({target, direction: "upstream"}) to find dependents
|
- [ ] gitnexus_impact({target, direction: "upstream"}) to find dependents
|
||||||
- [ ] Review d=1 items first (these WILL BREAK)
|
- [ ] Review d=1 items first (these WILL BREAK)
|
||||||
- [ ] Check high-confidence (>0.8) dependencies
|
- [ ] Check high-confidence (>0.8) dependencies
|
||||||
- [ ] READ processes to check affected execution flows
|
- [ ] READ processes to check affected execution flows
|
||||||
- [ ] detect_changes() for pre-commit check
|
- [ ] gitnexus_detect_changes() for pre-commit check
|
||||||
- [ ] Assess risk level and report to user
|
- [ ] Assess risk level and report to user
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -55,10 +55,10 @@ description: "Use when the user wants to know what will break if they change som
|
|||||||
|
|
||||||
## Tools
|
## Tools
|
||||||
|
|
||||||
**impact** — the primary tool for symbol blast radius:
|
**gitnexus_impact** — the primary tool for symbol blast radius:
|
||||||
|
|
||||||
```
|
```
|
||||||
impact({
|
gitnexus_impact({
|
||||||
target: "validateUser",
|
target: "validateUser",
|
||||||
direction: "upstream",
|
direction: "upstream",
|
||||||
minConfidence: 0.8,
|
minConfidence: 0.8,
|
||||||
@@ -73,10 +73,10 @@ impact({
|
|||||||
- authRouter (src/routes/auth.ts:22) [CALLS, 95%]
|
- authRouter (src/routes/auth.ts:22) [CALLS, 95%]
|
||||||
```
|
```
|
||||||
|
|
||||||
**detect_changes** — git-diff based impact analysis:
|
**gitnexus_detect_changes** — git-diff based impact analysis:
|
||||||
|
|
||||||
```
|
```
|
||||||
detect_changes({scope: "staged"})
|
gitnexus_detect_changes({scope: "staged"})
|
||||||
|
|
||||||
→ Changed: 5 symbols in 3 files
|
→ Changed: 5 symbols in 3 files
|
||||||
→ Affected: LoginFlow, TokenRefresh, APIMiddlewarePipeline
|
→ Affected: LoginFlow, TokenRefresh, APIMiddlewarePipeline
|
||||||
@@ -86,7 +86,7 @@ detect_changes({scope: "staged"})
|
|||||||
## Example: "What breaks if I change validateUser?"
|
## Example: "What breaks if I change validateUser?"
|
||||||
|
|
||||||
```
|
```
|
||||||
1. impact({target: "validateUser", direction: "upstream"})
|
1. gitnexus_impact({target: "validateUser", direction: "upstream"})
|
||||||
→ d=1: loginHandler, apiMiddleware (WILL BREAK)
|
→ d=1: loginHandler, apiMiddleware (WILL BREAK)
|
||||||
→ d=2: authRouter, sessionManager (LIKELY AFFECTED)
|
→ d=2: authRouter, sessionManager (LIKELY AFFECTED)
|
||||||
|
|
||||||
|
|||||||
@@ -16,78 +16,78 @@ description: "Use when the user wants to rename, extract, split, move, or restru
|
|||||||
## Workflow
|
## Workflow
|
||||||
|
|
||||||
```
|
```
|
||||||
1. impact({target: "X", direction: "upstream"}) → Map all dependents
|
1. gitnexus_impact({target: "X", direction: "upstream"}) → Map all dependents
|
||||||
2. query({query: "X"}) → Find execution flows involving X
|
2. gitnexus_query({query: "X"}) → Find execution flows involving X
|
||||||
3. context({name: "X"}) → See all incoming/outgoing refs
|
3. gitnexus_context({name: "X"}) → See all incoming/outgoing refs
|
||||||
4. Plan update order: interfaces → implementations → callers → tests
|
4. Plan update order: interfaces → implementations → callers → tests
|
||||||
```
|
```
|
||||||
|
|
||||||
> If "Index is stale" → run `node .gitnexus/run.cjs analyze` in terminal.
|
> If "Index is stale" → run `npx gitnexus analyze` in terminal.
|
||||||
|
|
||||||
## Checklists
|
## Checklists
|
||||||
|
|
||||||
### Rename Symbol
|
### Rename Symbol
|
||||||
|
|
||||||
```
|
```
|
||||||
- [ ] rename({symbol_name: "oldName", new_name: "newName", dry_run: true}) — preview all edits
|
- [ ] gitnexus_rename({symbol_name: "oldName", new_name: "newName", dry_run: true}) — preview all edits
|
||||||
- [ ] Review graph edits (high confidence) and ast_search edits (review carefully)
|
- [ ] Review graph edits (high confidence) and ast_search edits (review carefully)
|
||||||
- [ ] If satisfied: rename({..., dry_run: false}) — apply edits
|
- [ ] If satisfied: gitnexus_rename({..., dry_run: false}) — apply edits
|
||||||
- [ ] detect_changes() — verify only expected files changed
|
- [ ] gitnexus_detect_changes() — verify only expected files changed
|
||||||
- [ ] Run tests for affected processes
|
- [ ] Run tests for affected processes
|
||||||
```
|
```
|
||||||
|
|
||||||
### Extract Module
|
### Extract Module
|
||||||
|
|
||||||
```
|
```
|
||||||
- [ ] context({name: target}) — see all incoming/outgoing refs
|
- [ ] gitnexus_context({name: target}) — see all incoming/outgoing refs
|
||||||
- [ ] impact({target, direction: "upstream"}) — find all external callers
|
- [ ] gitnexus_impact({target, direction: "upstream"}) — find all external callers
|
||||||
- [ ] Define new module interface
|
- [ ] Define new module interface
|
||||||
- [ ] Extract code, update imports
|
- [ ] Extract code, update imports
|
||||||
- [ ] detect_changes() — verify affected scope
|
- [ ] gitnexus_detect_changes() — verify affected scope
|
||||||
- [ ] Run tests for affected processes
|
- [ ] Run tests for affected processes
|
||||||
```
|
```
|
||||||
|
|
||||||
### Split Function/Service
|
### Split Function/Service
|
||||||
|
|
||||||
```
|
```
|
||||||
- [ ] context({name: target}) — understand all callees
|
- [ ] gitnexus_context({name: target}) — understand all callees
|
||||||
- [ ] Group callees by responsibility
|
- [ ] Group callees by responsibility
|
||||||
- [ ] impact({target, direction: "upstream"}) — map callers to update
|
- [ ] gitnexus_impact({target, direction: "upstream"}) — map callers to update
|
||||||
- [ ] Create new functions/services
|
- [ ] Create new functions/services
|
||||||
- [ ] Update callers
|
- [ ] Update callers
|
||||||
- [ ] detect_changes() — verify affected scope
|
- [ ] gitnexus_detect_changes() — verify affected scope
|
||||||
- [ ] Run tests for affected processes
|
- [ ] Run tests for affected processes
|
||||||
```
|
```
|
||||||
|
|
||||||
## Tools
|
## Tools
|
||||||
|
|
||||||
**rename** — automated multi-file rename:
|
**gitnexus_rename** — automated multi-file rename:
|
||||||
|
|
||||||
```
|
```
|
||||||
rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
|
gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
|
||||||
→ 12 edits across 8 files
|
→ 12 edits across 8 files
|
||||||
→ 10 graph edits (high confidence), 2 ast_search edits (review)
|
→ 10 graph edits (high confidence), 2 ast_search edits (review)
|
||||||
→ Changes: [{file_path, edits: [{line, old_text, new_text, confidence}]}]
|
→ Changes: [{file_path, edits: [{line, old_text, new_text, confidence}]}]
|
||||||
```
|
```
|
||||||
|
|
||||||
**impact** — map all dependents first:
|
**gitnexus_impact** — map all dependents first:
|
||||||
|
|
||||||
```
|
```
|
||||||
impact({target: "validateUser", direction: "upstream"})
|
gitnexus_impact({target: "validateUser", direction: "upstream"})
|
||||||
→ d=1: loginHandler, apiMiddleware, testUtils
|
→ d=1: loginHandler, apiMiddleware, testUtils
|
||||||
→ Affected Processes: LoginFlow, TokenRefresh
|
→ Affected Processes: LoginFlow, TokenRefresh
|
||||||
```
|
```
|
||||||
|
|
||||||
**detect_changes** — verify your changes after refactoring:
|
**gitnexus_detect_changes** — verify your changes after refactoring:
|
||||||
|
|
||||||
```
|
```
|
||||||
detect_changes({scope: "all"})
|
gitnexus_detect_changes({scope: "all"})
|
||||||
→ Changed: 8 files, 12 symbols
|
→ Changed: 8 files, 12 symbols
|
||||||
→ Affected processes: LoginFlow, TokenRefresh
|
→ Affected processes: LoginFlow, TokenRefresh
|
||||||
→ Risk: MEDIUM
|
→ Risk: MEDIUM
|
||||||
```
|
```
|
||||||
|
|
||||||
**cypher** — custom reference queries:
|
**gitnexus_cypher** — custom reference queries:
|
||||||
|
|
||||||
```cypher
|
```cypher
|
||||||
MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "validateUser"})
|
MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "validateUser"})
|
||||||
@@ -98,24 +98,24 @@ RETURN caller.name, caller.filePath ORDER BY caller.filePath
|
|||||||
|
|
||||||
| Risk Factor | Mitigation |
|
| Risk Factor | Mitigation |
|
||||||
| ------------------- | ----------------------------------------- |
|
| ------------------- | ----------------------------------------- |
|
||||||
| Many callers (>5) | Use rename for automated updates |
|
| Many callers (>5) | Use gitnexus_rename for automated updates |
|
||||||
| Cross-area refs | Use detect_changes after to verify scope |
|
| Cross-area refs | Use detect_changes after to verify scope |
|
||||||
| String/dynamic refs | query to find them |
|
| String/dynamic refs | gitnexus_query to find them |
|
||||||
| External/public API | Version and deprecate properly |
|
| External/public API | Version and deprecate properly |
|
||||||
|
|
||||||
## Example: Rename `validateUser` to `authenticateUser`
|
## Example: Rename `validateUser` to `authenticateUser`
|
||||||
|
|
||||||
```
|
```
|
||||||
1. rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
|
1. gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
|
||||||
→ 12 edits: 10 graph (safe), 2 ast_search (review)
|
→ 12 edits: 10 graph (safe), 2 ast_search (review)
|
||||||
→ Files: validator.ts, login.ts, middleware.ts, config.json...
|
→ Files: validator.ts, login.ts, middleware.ts, config.json...
|
||||||
|
|
||||||
2. Review ast_search edits (config.json: dynamic reference!)
|
2. Review ast_search edits (config.json: dynamic reference!)
|
||||||
|
|
||||||
3. rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: false})
|
3. gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: false})
|
||||||
→ Applied 12 edits across 8 files
|
→ Applied 12 edits across 8 files
|
||||||
|
|
||||||
4. detect_changes({scope: "all"})
|
4. gitnexus_detect_changes({scope: "all"})
|
||||||
→ Affected: LoginFlow, TokenRefresh
|
→ Affected: LoginFlow, TokenRefresh
|
||||||
→ Risk: MEDIUM — run tests for these flows
|
→ Risk: MEDIUM — run tests for these flows
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import { createHash } from 'node:crypto';
|
|
||||||
import { access, readFile } from 'node:fs/promises';
|
|
||||||
import { join } from 'node:path';
|
|
||||||
import { envName, latestSuccess, recordsRoot, snapshotRoot } from './release-store.mjs';
|
|
||||||
|
|
||||||
const environment = envName(process.env.RELEASE_ENVIRONMENT);
|
|
||||||
const commitSha = process.env.RELEASE_SHA;
|
|
||||||
const record = await latestSuccess(environment, 'nacos');
|
|
||||||
if (!commitSha || record.commitSha !== commitSha || record.status !== 'success') throw new Error(`没有提交 ${commitSha} 对应的成功 Nacos 发布`);
|
|
||||||
if (!record.activeSnapshotId || !record.snapshotId || !Array.isArray(record.files) || record.files.length === 0 || record.files.some((file) => !file.sha256 || !file.dataId || !file.namespace)) throw new Error('Nacos 发布记录不完整');
|
|
||||||
const destinations = environment === 'prod' ? ['prod-center1', 'prod-center2'] : [environment];
|
|
||||||
for (const destination of destinations) for (const file of record.files) {
|
|
||||||
const path = join(snapshotRoot(environment, record.activeSnapshotId), destination, file.namespace, 'DEFAULT_GROUP', file.dataId);
|
|
||||||
const content = await readFile(path, 'utf8');
|
|
||||||
if (createHash('sha256').update(content, 'utf8').digest('hex') !== file.sha256) throw new Error(`Nacos 发布快照摘要不匹配:${destination}/${file.namespace}/${file.dataId}`);
|
|
||||||
}
|
|
||||||
await access(join(recordsRoot(environment), 'latest-success-nacos.json'));
|
|
||||||
console.log(JSON.stringify(record));
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
const workflow = process.argv[2];
|
|
||||||
const ref = process.argv[3] || process.env.GITHUB_REF_NAME;
|
|
||||||
if (!workflow || !ref) throw new Error('用法:node dispatch-workflow.mjs <workflow.yml> <ref>');
|
|
||||||
const token = process.env.GITHUB_TOKEN;
|
|
||||||
if (!token) throw new Error('缺少 GITHUB_TOKEN');
|
|
||||||
const server = process.env.GITHUB_SERVER_URL || 'http://192.168.5.15:3000';
|
|
||||||
const repository = process.env.GITHUB_REPOSITORY || 'xiaowang/JayuCloud';
|
|
||||||
const inputs = Object.fromEntries(Object.entries(process.env).filter(([key]) => key.startsWith('DISPATCH_INPUT_')).map(([key, value]) => [key.slice('DISPATCH_INPUT_'.length).toLowerCase(), value]));
|
|
||||||
if (process.env.AUTO_ROLLBACK === 'true') inputs.auto_rollback = 'true';
|
|
||||||
const isNacosRollback = /^(回退dev环境nacos配置|回退sit环境nacos配置|回退prod环境nacos配置)\.yml$/.test(workflow);
|
|
||||||
if (isNacosRollback && !inputs.snapshot_id && process.env.RELEASE_STORE_ROOT && (process.env.RELEASE_ENVIRONMENT || process.env.NACOS_ENVIRONMENT)) {
|
|
||||||
try { inputs.snapshot_id = JSON.parse(await (await import('node:fs/promises')).readFile(`${process.env.RELEASE_STORE_ROOT}/records/${process.env.RELEASE_ENVIRONMENT || process.env.NACOS_ENVIRONMENT}/pending-nacos.json`, 'utf8')).snapshotId; } catch {}
|
|
||||||
}
|
|
||||||
if (isNacosRollback && process.env.AUTO_ROLLBACK === 'true' && !inputs.snapshot_id) {
|
|
||||||
console.log('没有待处理的 Nacos 发布快照,无需触发 Nacos 回退');
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
const response = await fetch(`${server}/api/v1/repos/${repository}/actions/workflows/${workflow}/dispatches`, { method: 'POST', headers: { Authorization: `token ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ ref, inputs }) });
|
|
||||||
if (!response.ok && response.status !== 204) throw new Error(`触发 ${workflow} 失败:HTTP ${response.status} ${await response.text()}`);
|
|
||||||
console.log(`已触发 ${workflow} @ ${ref}`);
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
import { createHash } from 'node:crypto';
|
|
||||||
import { mkdir, readFile, readdir, rm } from 'node:fs/promises';
|
|
||||||
import { join, relative, sep } from 'node:path';
|
|
||||||
import { atomicWrite, envName, listYamlFiles, recordsRoot, snapshotRoot, writeJson } from './release-store.mjs';
|
|
||||||
|
|
||||||
const environment = envName(process.env.NACOS_ENVIRONMENT);
|
|
||||||
const group = 'DEFAULT_GROUP';
|
|
||||||
const root = process.cwd();
|
|
||||||
const configRoot = join(root, 'nacos', 'namespaces', environment);
|
|
||||||
const files = await listYamlFiles(configRoot);
|
|
||||||
if (!files.length) throw new Error(`没有可发布的 ${environment} YAML 配置`);
|
|
||||||
const destinations = (environment === 'prod' ? [['NACOS_PROD', 'prod-center1', 2], ['NACOS_DR', 'prod-center2', 1]] : [[environment === 'dev' ? 'NACOS_DEV' : 'NACOS_SIT', environment, 1]]).map(([prefix, id, nodes]) => {
|
|
||||||
const urls = required(`${prefix}_URLS`).split(',').map(normalize).filter(Boolean);
|
|
||||||
if (urls.length < nodes) throw new Error(`${prefix} Nacos 地址不足`);
|
|
||||||
return { prefix, id, urls, token: null, nodes };
|
|
||||||
});
|
|
||||||
for (const destination of destinations) destination.token = await login(destination.urls[0], required(`${destination.prefix}_USERNAME`), required(`${destination.prefix}_PASSWORD`));
|
|
||||||
const groupName = group;
|
|
||||||
const runId = process.env.GITHUB_RUN_ID || 'manual';
|
|
||||||
const commitSha = process.env.GITHUB_SHA || 'unknown';
|
|
||||||
const recordRoot = recordsRoot(environment);
|
|
||||||
const snapshotId = `${new Date().toISOString().replaceAll(/[:.]/g, '-')}-${runId}`;
|
|
||||||
const releaseId = `${environment}-${commitSha.slice(0, 12)}-${runId}`;
|
|
||||||
const snapshot = snapshotRoot(environment, snapshotId);
|
|
||||||
const activeSnapshotId = `active-${releaseId}`;
|
|
||||||
const activeSnapshot = snapshotRoot(environment, activeSnapshotId);
|
|
||||||
await mkdir(snapshot, { recursive: true });
|
|
||||||
await mkdir(activeSnapshot, { recursive: true });
|
|
||||||
const entries = [];
|
|
||||||
for (const file of files) {
|
|
||||||
const { namespace, dataId } = info(file);
|
|
||||||
const content = await readFile(file, 'utf8');
|
|
||||||
const entry = { namespace, dataId, sha256: sha256(content), previousSha256: {}, previousExists: {} };
|
|
||||||
entries.push(entry);
|
|
||||||
for (const destination of destinations) {
|
|
||||||
const response = await fetch(`${destination.urls[0]}/nacos/v1/cs/configs?${new URLSearchParams({ dataId, group: groupName, tenant: namespace, accessToken: destination.token })}`);
|
|
||||||
if (!response.ok && response.status !== 404) throw new Error(`读取当前 Nacos 配置失败:${destination.prefix}/${namespace}/${dataId} HTTP ${response.status}`);
|
|
||||||
const oldContent = await response.text();
|
|
||||||
entry.previousExists[destination.id] = response.status !== 404;
|
|
||||||
entry.previousSha256[destination.id] = sha256(oldContent);
|
|
||||||
await atomicWrite(join(snapshot, destination.id, namespace, groupName, dataId), oldContent);
|
|
||||||
await atomicWrite(join(activeSnapshot, destination.id, namespace, groupName, dataId), content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await writeJson(join(recordRoot, 'pending-nacos.json'), { environment, snapshotId, activeSnapshotId, commitSha, runId, releaseId, files: entries, createdAt: new Date().toISOString() });
|
|
||||||
try {
|
|
||||||
for (const file of files) {
|
|
||||||
const { namespace, dataId } = info(file);
|
|
||||||
const content = await readFile(file, 'utf8');
|
|
||||||
for (const destination of destinations) {
|
|
||||||
const response = await fetch(`${destination.urls[0]}/nacos/v1/cs/configs?accessToken=${encodeURIComponent(destination.token)}`, { method: 'POST', body: new URLSearchParams({ dataId, group: groupName, tenant: namespace, type: 'yaml', content }) });
|
|
||||||
const result = await response.text();
|
|
||||||
if (!response.ok || result.trim() !== 'true') throw new Error(`发布失败:${destination.prefix}/${namespace}/${dataId} HTTP ${response.status}`);
|
|
||||||
await verify(destination, namespace, dataId, content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const previous = await optionalJson(join(recordRoot, 'latest-success-nacos.json'));
|
|
||||||
const record = { environment, status: 'success', commitSha, runId, releaseId, snapshotId, activeSnapshotId, previousReleaseId: previous?.releaseId || null, files: entries, publishedAt: new Date().toISOString() };
|
|
||||||
await writeJson(join(recordRoot, 'latest-success-nacos.json'), record);
|
|
||||||
await writeJson(join(recordRoot, 'nacos', `${releaseId}.json`), record);
|
|
||||||
await rm(join(recordRoot, 'pending-nacos.json'), { force: true });
|
|
||||||
console.log(`已发布并校验 ${environment} Nacos,回退快照 ${snapshotId}`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error.message);
|
|
||||||
console.error(`AUTO_ROLLBACK_SNAPSHOT_ID=${snapshotId}`);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
function required(name) { if (!process.env[name]) throw new Error(`缺少环境变量 ${name}`); return process.env[name]; }
|
|
||||||
function normalize(value) { return value.replace(/\/+$/, '').replace(/\/nacos$/, ''); }
|
|
||||||
function sha256(value) { return createHash('sha256').update(value, 'utf8').digest('hex'); }
|
|
||||||
function info(file) {
|
|
||||||
const parts = relative(configRoot, file).split(sep);
|
|
||||||
if (parts.length !== 3 || parts[1] !== group || !parts[0] || !parts[2]) throw new Error(`配置路径无效,必须为 namespace/${group}/dataId:${file}`);
|
|
||||||
return { namespace: parts[0], dataId: parts[2] };
|
|
||||||
}
|
|
||||||
async function optionalJson(path) { try { return JSON.parse(await readFile(path, 'utf8')); } catch { return null; } }
|
|
||||||
async function login(base, user, password) { const response = await fetch(`${base}/nacos/v1/auth/login`, { method: 'POST', body: new URLSearchParams({ username: user, password }) }); if (!response.ok) throw new Error(`Nacos 登录失败:HTTP ${response.status}`); const result = await response.json(); if (!result.accessToken) throw new Error('Nacos 登录响应缺少 accessToken'); return result.accessToken; }
|
|
||||||
async function verify(destination, namespace, dataId, expected) { const expectedHash = sha256(expected); for (const base of destination.urls) { let status = 0; let content = ''; for (let attempt = 0; attempt < 3; attempt += 1) { const response = await fetch(`${base}/nacos/v1/cs/configs?${new URLSearchParams({ dataId, group: groupName, tenant: namespace, accessToken: destination.token })}`); status = response.status; content = await response.text(); if (status === 200 && sha256(content) === expectedHash) break; await new Promise((resolve) => setTimeout(resolve, 1000)); } if (status !== 200 || sha256(content) !== expectedHash) throw new Error(`Nacos 校验失败:${destination.prefix}/${base}/${namespace}/${dataId}`); } }
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
import { createHash } from 'node:crypto';
|
|
||||||
import { readFile, readdir } from 'node:fs/promises';
|
|
||||||
import { join } from 'node:path';
|
|
||||||
import { envName, latestSuccess, recordsRoot, writeJson } from './release-store.mjs';
|
|
||||||
|
|
||||||
const environment = envName(process.env.RELEASE_ENVIRONMENT);
|
|
||||||
const commitSha = process.env.RELEASE_SHA;
|
|
||||||
const nacos = await latestSuccess(environment, 'nacos');
|
|
||||||
const packageDir = process.env.PACKAGE_DIRECTORY;
|
|
||||||
if (!commitSha || nacos.commitSha !== commitSha || !packageDir) throw new Error('部署记录参数不完整');
|
|
||||||
if (nacos.status !== 'success' || !nacos.files?.length || !nacos.activeSnapshotId) throw new Error('Nacos 发布已回退或发布记录不完整');
|
|
||||||
const manifestPath = await findFile(packageDir, 'manifest.json');
|
|
||||||
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
||||||
const artifactPaths = {};
|
|
||||||
for (const [name, fileName] of Object.entries({ core: 'JC-Salon-Core.jar', gateway: 'JC-Salon-Gateway.jar', frontend: 'jc-salon-frontend-dist.tar.gz' })) {
|
|
||||||
const artifactPath = await findFile(packageDir, fileName);
|
|
||||||
const sha256 = createHash('sha256').update(await readFile(artifactPath)).digest('hex');
|
|
||||||
const expected = manifest.artifacts?.find((item) => item.Path?.endsWith(fileName))?.Sha256?.toLowerCase();
|
|
||||||
if (!expected || expected !== sha256) throw new Error(`发布包摘要不匹配:${fileName}`);
|
|
||||||
artifactPaths[name] = { path: artifactPath, sha256 };
|
|
||||||
}
|
|
||||||
const previous = await optional(join(recordsRoot(environment), 'latest-success-deploy.json'));
|
|
||||||
const releaseId = `${environment}-${commitSha.slice(0, 12)}-${process.env.GITHUB_RUN_ID || 'manual'}`;
|
|
||||||
const record = { environment, status: 'success', commitSha, releaseId, nacosReleaseId: nacos.releaseId, snapshotId: nacos.snapshotId, activeSnapshotId: nacos.activeSnapshotId, packageDir, manifestPath, artifacts: artifactPaths, previousReleaseId: previous?.releaseId || null, runId: process.env.GITHUB_RUN_ID || 'manual', deployedAt: new Date().toISOString() };
|
|
||||||
await writeJson(join(recordsRoot(environment), 'deploy', `${releaseId}.json`), record);
|
|
||||||
await writeJson(join(recordsRoot(environment), 'latest-success-deploy.json'), record);
|
|
||||||
console.log(JSON.stringify(record));
|
|
||||||
async function optional(path) { try { return JSON.parse(await readFile(path, 'utf8')); } catch { return null; } }
|
|
||||||
async function findFile(root, name) {
|
|
||||||
for (const entry of await readdir(root, { withFileTypes: true })) {
|
|
||||||
const path = join(root, entry.name);
|
|
||||||
if (entry.isDirectory()) { const nested = await optionalFind(path, name); if (nested) return nested; }
|
|
||||||
else if (entry.name === name) return path;
|
|
||||||
}
|
|
||||||
throw new Error(`发布包缺少 ${name}`);
|
|
||||||
}
|
|
||||||
async function optionalFind(root, name) { try { return await findFile(root, name); } catch { return null; } }
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { join } from 'node:path';
|
|
||||||
import { envName, recordsRoot, readJson, writeJson } from './release-store.mjs';
|
|
||||||
|
|
||||||
const environment = envName(process.env.RELEASE_ENVIRONMENT);
|
|
||||||
const releaseId = process.env.ROLLBACK_RELEASE_ID;
|
|
||||||
if (!releaseId) throw new Error('缺少 ROLLBACK_RELEASE_ID');
|
|
||||||
const record = await readJson(join(recordsRoot(environment), 'deploy', `${releaseId}.json`));
|
|
||||||
if (record.status !== 'success' || !record.packageDir || !record.activeSnapshotId) throw new Error('目标回退版本记录不完整');
|
|
||||||
await writeJson(join(recordsRoot(environment), 'latest-success-deploy.json'), { ...record, restoredAt: new Date().toISOString() });
|
|
||||||
console.log(`已将 ${environment} 成功版本指针更新到 ${releaseId}`);
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
import { mkdir, readFile, readdir, rename, writeFile } from 'node:fs/promises';
|
|
||||||
import { dirname, join, resolve } from 'node:path';
|
|
||||||
|
|
||||||
export const storeRoot = process.env.RELEASE_STORE_ROOT || '/salon-release';
|
|
||||||
|
|
||||||
export function envName(value = process.env.NACOS_ENVIRONMENT) {
|
|
||||||
if (!['dev', 'sit', 'prod'].includes(value)) throw new Error(`不支持的环境:${value}`);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function environmentRoot(environment = envName()) {
|
|
||||||
return join(storeRoot, environment);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function snapshotRoot(environment = envName(), snapshotId) {
|
|
||||||
return join(storeRoot, 'nacos-snapshots', environment, snapshotId);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function recordsRoot(environment = envName()) {
|
|
||||||
return join(storeRoot, 'records', environment);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function atomicWrite(path, content) {
|
|
||||||
await mkdir(dirname(path), { recursive: true });
|
|
||||||
const temp = `${path}.tmp-${process.pid}-${Date.now()}`;
|
|
||||||
await writeFile(temp, content, 'utf8');
|
|
||||||
await rename(temp, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function readJson(path) {
|
|
||||||
return JSON.parse(await readFile(path, 'utf8'));
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function writeJson(path, value) {
|
|
||||||
await atomicWrite(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function latestSuccess(environment = envName(), kind = 'nacos') {
|
|
||||||
const path = join(recordsRoot(environment), `latest-success-${kind}.json`);
|
|
||||||
return readJson(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function releaseRecord(environment, kind, releaseId) {
|
|
||||||
return readJson(join(recordsRoot(environment), kind, `${releaseId}.json`));
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function listYamlFiles(root) {
|
|
||||||
const result = [];
|
|
||||||
for (const entry of await readdir(root, { withFileTypes: true })) {
|
|
||||||
const path = join(root, entry.name);
|
|
||||||
if (entry.isDirectory()) result.push(...await listYamlFiles(path));
|
|
||||||
else if (entry.isFile() && entry.name.endsWith('.yaml')) result.push(path);
|
|
||||||
}
|
|
||||||
return result.sort();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function safeRelative(root, path) {
|
|
||||||
const value = resolve(path);
|
|
||||||
const base = resolve(root);
|
|
||||||
if (!value.startsWith(`${base}/`) && !value.startsWith(`${base}\\`)) throw new Error(`路径越界:${path}`);
|
|
||||||
return value.slice(base.length + 1).replaceAll('\\', '/');
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import { createHash } from 'node:crypto';
|
|
||||||
import { readFile, readdir, rm } from 'node:fs/promises';
|
|
||||||
import { join } from 'node:path';
|
|
||||||
import { envName, recordsRoot, snapshotRoot, writeJson } from './release-store.mjs';
|
|
||||||
|
|
||||||
const environment = envName(process.env.NACOS_ENVIRONMENT);
|
|
||||||
const group = 'DEFAULT_GROUP';
|
|
||||||
const destinations = environment === 'prod' ? [['NACOS_PROD', 'prod-center1'], ['NACOS_DR', 'prod-center2']] : [[environment === 'dev' ? 'NACOS_DEV' : 'NACOS_SIT', environment]];
|
|
||||||
const targets = [];
|
|
||||||
for (const [prefix, id] of destinations) {
|
|
||||||
const urls = required(`${prefix}_URLS`).split(',').map(normalize).filter(Boolean);
|
|
||||||
if (!urls.length) throw new Error(`${prefix}_URLS 为空`);
|
|
||||||
targets.push({ prefix, id, urls, token: await login(urls[0], required(`${prefix}_USERNAME`), required(`${prefix}_PASSWORD`)) });
|
|
||||||
}
|
|
||||||
const root = recordsRoot(environment);
|
|
||||||
const pending = await optional(join(root, 'pending-nacos.json'));
|
|
||||||
const latest = await optional(join(root, 'latest-success-nacos.json'));
|
|
||||||
let selected = process.env.NACOS_RELEASE_ID
|
|
||||||
? await optional(join(root, 'nacos', `${process.env.NACOS_RELEASE_ID}.json`))
|
|
||||||
: null;
|
|
||||||
if (process.env.NACOS_RELEASE_ID && !selected) throw new Error(`找不到 Nacos 发布记录:${process.env.NACOS_RELEASE_ID}`);
|
|
||||||
if (!process.env.NACOS_SNAPSHOT_ID && !pending && !selected && latest?.previousReleaseId) selected = await optional(join(root, 'nacos', `${latest.previousReleaseId}.json`));
|
|
||||||
const snapshotId = process.env.NACOS_SNAPSHOT_ID || (selected ? selected.activeSnapshotId : pending?.snapshotId || latest?.snapshotId);
|
|
||||||
if (!snapshotId) throw new Error(`没有 ${environment} Nacos 回退快照`);
|
|
||||||
if (!selected && !pending) selected = await findSnapshotRecord(join(root, 'nacos'), snapshotId);
|
|
||||||
const snapshot = snapshotRoot(environment, snapshotId);
|
|
||||||
const entries = selected?.files || pending?.files || latest?.files || [];
|
|
||||||
const selectedIsActive = selected?.activeSnapshotId === snapshotId;
|
|
||||||
if (!entries.length) throw new Error('回退记录缺少配置清单');
|
|
||||||
for (const target of targets) {
|
|
||||||
for (const entry of entries) {
|
|
||||||
for (const base of target.urls) {
|
|
||||||
const exists = selectedIsActive || entry.previousExists?.[target.id] !== false;
|
|
||||||
const path = join(snapshot, target.id, entry.namespace, group, entry.dataId);
|
|
||||||
const content = exists ? await readFile(path, 'utf8') : '';
|
|
||||||
const expectedHash = selectedIsActive ? entry.sha256 : entry.previousSha256?.[target.id];
|
|
||||||
if (exists && (!expectedHash || sha256(content) !== expectedHash)) throw new Error(`回退快照摘要不匹配:${target.id}/${entry.namespace}/${entry.dataId}`);
|
|
||||||
const query = new URLSearchParams({ dataId: entry.dataId, group, tenant: entry.namespace, accessToken: target.token });
|
|
||||||
const response = exists
|
|
||||||
? await fetch(`${base}/nacos/v1/cs/configs?accessToken=${encodeURIComponent(target.token)}`, { method: 'POST', body: new URLSearchParams({ dataId: entry.dataId, group, tenant: entry.namespace, type: 'yaml', content }) })
|
|
||||||
: await fetch(`${base}/nacos/v1/cs/configs?${query}`, { method: 'DELETE' });
|
|
||||||
if (!response.ok || (exists && (await response.text()).trim() !== 'true')) throw new Error(`回退失败:${target.id}/${entry.namespace}/${entry.dataId}`);
|
|
||||||
const check = await fetch(`${base}/nacos/v1/cs/configs?${new URLSearchParams({ dataId: entry.dataId, group, tenant: entry.namespace, accessToken: target.token })}`);
|
|
||||||
const actual = await check.text();
|
|
||||||
if (exists ? (!check.ok || sha256(actual) !== sha256(content)) : check.status !== 404) throw new Error(`回退摘要校验失败:${target.id}/${entry.namespace}/${entry.dataId}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await writeJson(join(root, 'last-rollback.json'), { environment, snapshotId, source: process.env.AUTO_ROLLBACK === 'true' ? 'automatic' : 'manual', rollbackAt: new Date().toISOString() });
|
|
||||||
if (selectedIsActive && selected) await writeJson(join(root, 'latest-success-nacos.json'), selected);
|
|
||||||
await rm(join(root, 'pending-nacos.json'), { force: true });
|
|
||||||
console.log(`已回退 ${environment} Nacos:${snapshotId}`);
|
|
||||||
function required(name) { if (!process.env[name]) throw new Error(`缺少环境变量 ${name}`); return process.env[name]; }
|
|
||||||
function normalize(value) { return value.replace(/\/+$/, '').replace(/\/nacos$/, ''); }
|
|
||||||
function sha256(value) { return createHash('sha256').update(value, 'utf8').digest('hex'); }
|
|
||||||
async function optional(path) { try { return JSON.parse(await readFile(path, 'utf8')); } catch { return null; } }
|
|
||||||
async function findSnapshotRecord(directory, id) {
|
|
||||||
try {
|
|
||||||
for (const file of await readdir(directory)) {
|
|
||||||
if (!file.endsWith('.json')) continue;
|
|
||||||
const record = await optional(join(directory, file));
|
|
||||||
if (record?.snapshotId === id || record?.activeSnapshotId === id) return record;
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
async function login(base, user, password) { const response = await fetch(`${base}/nacos/v1/auth/login`, { method: 'POST', body: new URLSearchParams({ username: user, password }) }); if (!response.ok) throw new Error(`Nacos 登录失败:HTTP ${response.status}`); const result = await response.json(); if (!result.accessToken) throw new Error('Nacos 登录响应缺少 accessToken'); return result.accessToken; }
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
name: 生产环境回退上一个版本
|
|
||||||
|
|
||||||
"on":
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
auto_rollback:
|
|
||||||
description: 是否由自动失败流程触发
|
|
||||||
required: false
|
|
||||||
type: boolean
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-prod
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
rollback:
|
|
||||||
runs-on: jayucloud
|
|
||||||
container:
|
|
||||||
options: >-
|
|
||||||
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
|
|
||||||
env:
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
RELEASE_ENVIRONMENT: prod
|
|
||||||
RELEASE_STORE_ROOT: /salon-release
|
|
||||||
NACOS_ENVIRONMENT: prod
|
|
||||||
AUTO_ROLLBACK: ${{ inputs.auto_rollback }}
|
|
||||||
WEB_TARGET_HOST: 10.66.0.3
|
|
||||||
WEB_TARGET_PORT: 22
|
|
||||||
WEB_TARGET_USER: root
|
|
||||||
WEB_REMOTE_DIR: /opt/jc-salon-frontend
|
|
||||||
SALON_PROD_SSH_PASSWORD: ${{ secrets.SALON_PROD_SSH_PASSWORD }}
|
|
||||||
NACOS_PROD_URLS: ${{ secrets.NACOS_PROD_URLS }}
|
|
||||||
NACOS_PROD_USERNAME: ${{ secrets.NACOS_PROD_USERNAME }}
|
|
||||||
NACOS_PROD_PASSWORD: ${{ secrets.NACOS_PROD_PASSWORD }}
|
|
||||||
NACOS_DR_URLS: ${{ secrets.NACOS_DR_URLS }}
|
|
||||||
NACOS_DR_USERNAME: ${{ secrets.NACOS_DR_USERNAME }}
|
|
||||||
NACOS_DR_PASSWORD: ${{ secrets.NACOS_DR_PASSWORD }}
|
|
||||||
steps:
|
|
||||||
- name: 检出回退脚本
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
git init .
|
|
||||||
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
||||||
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$GITHUB_SHA"
|
|
||||||
git checkout --detach "$GITHUB_SHA"
|
|
||||||
- name: 读取上一成功版本
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
current=/salon-release/records/prod/latest-success-deploy.json
|
|
||||||
test -f "$current"
|
|
||||||
node - <<'NODE' >> "$GITHUB_ENV"
|
|
||||||
const fs = require('fs');
|
|
||||||
const latest = JSON.parse(fs.readFileSync('/salon-release/records/prod/latest-success-deploy.json'));
|
|
||||||
const id = process.env.AUTO_ROLLBACK === 'true' ? latest.releaseId : latest.previousReleaseId;
|
|
||||||
if (!id) throw new Error('没有可回退的 PROD 成功版本');
|
|
||||||
const target = JSON.parse(fs.readFileSync(`/salon-release/records/prod/deploy/${id}.json`));
|
|
||||||
console.log(`PACKAGE_DIRECTORY=${target.packageDir}`);
|
|
||||||
console.log(`ROLLBACK_SNAPSHOT_ID=${target.activeSnapshotId}`);
|
|
||||||
console.log(`ROLLBACK_RELEASE_ID=${target.releaseId}`);
|
|
||||||
console.log(`NACOS_RELEASE_ID=${target.nacosReleaseId}`);
|
|
||||||
NODE
|
|
||||||
- name: 安装 SSH 密码工具
|
|
||||||
shell: bash
|
|
||||||
run: apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sshpass
|
|
||||||
- name: 写入 PROD 目标清单
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
mkdir -p "$RUNNER_TEMP/salon-prod"
|
|
||||||
printf '[{"Name":"core01-01","Host":"192.168.10.24","Port":22,"User":"root","Environment":"prod"},{"Name":"core01-02","Host":"192.168.10.25","Port":22,"User":"root","Environment":"prod"},{"Name":"core01-03","Host":"192.168.20.16","Port":22,"User":"root","Environment":"prod"},{"Name":"gateway01-01","Host":"192.168.10.26","Port":22,"User":"root","Environment":"prod"},{"Name":"gateway01-02","Host":"192.168.10.27","Port":22,"User":"root","Environment":"prod"},{"Name":"gateway01-03","Host":"192.168.20.18","Port":22,"User":"root","Environment":"prod"},{"Name":"salon-web","Host":"%s","Port":%s,"User":"%s","Environment":"prod"}]\n' "$WEB_TARGET_HOST" "$WEB_TARGET_PORT" "$WEB_TARGET_USER" > "$RUNNER_TEMP/salon-prod/servers.json"
|
|
||||||
- name: 恢复 PROD Nacos
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
NACOS_SNAPSHOT_ID: ${{ env.ROLLBACK_SNAPSHOT_ID }}
|
|
||||||
NACOS_RELEASE_ID: ${{ env.NACOS_RELEASE_ID }}
|
|
||||||
AUTO_ROLLBACK: 'true'
|
|
||||||
NACOS_ROLLBACK_INVALIDATE: 'true'
|
|
||||||
run: node .gitea/scripts/rollback-nacos.mjs
|
|
||||||
- name: 恢复 PROD 应用
|
|
||||||
shell: pwsh
|
|
||||||
run: ./docs/scripts/deploy-jayucloud-salon-production.ps1 -Deploy -SkipDatabaseInit -RequireSystemd -PackageDirectory "$env:PACKAGE_DIRECTORY" -ServerInfoJsonPath "$env:RUNNER_TEMP/salon-prod/servers.json" -SshPassword "$env:SALON_PROD_SSH_PASSWORD" -CoreRemoteAppDir /opt/jc-salon-core -GatewayRemoteAppDir /opt/jc-salon-gateway -CorePattern '^core01-' -GatewayPattern '^gateway01-' -CoreServiceName jc-salon-core -GatewayServiceName jc-salon-gateway -WebTargetName salon-web -WebRemoteDir "$env:WEB_REMOTE_DIR" -PublicBaseUrl https://salon.yunail.art
|
|
||||||
- name: 记录回退后的成功版本
|
|
||||||
shell: bash
|
|
||||||
run: node .gitea/scripts/record-rollback.mjs
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
name: 测试环境回退上一个版本
|
|
||||||
|
|
||||||
"on":
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
auto_rollback:
|
|
||||||
description: 是否由自动失败流程触发
|
|
||||||
required: false
|
|
||||||
type: boolean
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-sit
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
rollback:
|
|
||||||
runs-on: jayucloud
|
|
||||||
container:
|
|
||||||
options: >-
|
|
||||||
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
|
|
||||||
env:
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
RELEASE_ENVIRONMENT: sit
|
|
||||||
RELEASE_STORE_ROOT: /salon-release
|
|
||||||
NACOS_ENVIRONMENT: sit
|
|
||||||
AUTO_ROLLBACK: ${{ inputs.auto_rollback }}
|
|
||||||
WEB_TARGET_HOST: 10.66.0.3
|
|
||||||
WEB_TARGET_PORT: 22
|
|
||||||
WEB_TARGET_USER: root
|
|
||||||
WEB_REMOTE_DIR: /opt/jc-salon-frontend-sit
|
|
||||||
SALON_PROD_SSH_PASSWORD: ${{ secrets.SALON_PROD_SSH_PASSWORD }}
|
|
||||||
NACOS_SIT_URLS: ${{ secrets.NACOS_SIT_URLS }}
|
|
||||||
NACOS_SIT_USERNAME: ${{ secrets.NACOS_SIT_USERNAME }}
|
|
||||||
NACOS_SIT_PASSWORD: ${{ secrets.NACOS_SIT_PASSWORD }}
|
|
||||||
steps:
|
|
||||||
- name: 检出回退脚本
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
run: |
|
|
||||||
git init .
|
|
||||||
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
||||||
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$GITHUB_SHA"
|
|
||||||
git checkout --detach "$GITHUB_SHA"
|
|
||||||
- name: 读取最近成功版本
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
test -f /salon-release/records/sit/latest-success-deploy.json
|
|
||||||
node - <<'NODE' >> "$GITHUB_ENV"
|
|
||||||
const fs = require('fs');
|
|
||||||
const latest = JSON.parse(fs.readFileSync('/salon-release/records/sit/latest-success-deploy.json'));
|
|
||||||
const id = process.env.AUTO_ROLLBACK === 'true' ? latest.releaseId : latest.previousReleaseId;
|
|
||||||
if (!id) throw new Error('没有可回退的 SIT 成功版本');
|
|
||||||
const target = JSON.parse(fs.readFileSync(`/salon-release/records/sit/deploy/${id}.json`));
|
|
||||||
console.log(`PACKAGE_DIRECTORY=${target.packageDir}`);
|
|
||||||
console.log(`ROLLBACK_SNAPSHOT_ID=${target.activeSnapshotId}`);
|
|
||||||
console.log(`ROLLBACK_RELEASE_ID=${target.releaseId}`);
|
|
||||||
console.log(`NACOS_RELEASE_ID=${target.nacosReleaseId}`);
|
|
||||||
NODE
|
|
||||||
- name: 安装 SSH 密码工具
|
|
||||||
shell: bash
|
|
||||||
run: apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sshpass
|
|
||||||
- name: 恢复 SIT Nacos
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
NACOS_SNAPSHOT_ID: ${{ env.ROLLBACK_SNAPSHOT_ID }}
|
|
||||||
NACOS_RELEASE_ID: ${{ env.NACOS_RELEASE_ID }}
|
|
||||||
AUTO_ROLLBACK: 'true'
|
|
||||||
NACOS_ROLLBACK_INVALIDATE: 'true'
|
|
||||||
run: node .gitea/scripts/rollback-nacos.mjs
|
|
||||||
- name: 执行 SIT 应用回退
|
|
||||||
shell: pwsh
|
|
||||||
run: ./docs/scripts/deploy-jayucloud-salon-production.ps1 -Deploy -SkipDatabaseInit -AllowSitTarget -RequireSystemd -PackageDirectory "$env:PACKAGE_DIRECTORY" -SshPassword "$env:SALON_PROD_SSH_PASSWORD" -CoreRemoteAppDir /opt/jc-salon-core-sit -GatewayRemoteAppDir /opt/jc-salon-gateway-sit -CorePattern '^sit-app01$' -GatewayPattern '^sit-app01$' -CoreServiceName jc-salon-core-sit -GatewayServiceName jc-salon-gateway-sit -CoreHealthPort 181 -GatewayHealthPort 180 -WebTargetName salon-web-sit -WebRemoteDir "$env:WEB_REMOTE_DIR" -PublicBaseUrl https://sit.yunail.art
|
|
||||||
- name: 记录回退后的成功版本
|
|
||||||
shell: bash
|
|
||||||
run: node .gitea/scripts/record-rollback.mjs
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
name: 回退开发环境 Nacos 配置
|
|
||||||
|
|
||||||
"on":
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
snapshot_id:
|
|
||||||
description: 可选快照 ID,留空使用待回退快照
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
auto_rollback:
|
|
||||||
description: 是否由自动失败流程触发
|
|
||||||
required: false
|
|
||||||
type: boolean
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-dev
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
rollback:
|
|
||||||
runs-on: jayucloud
|
|
||||||
container:
|
|
||||||
options: >-
|
|
||||||
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
|
|
||||||
env:
|
|
||||||
NACOS_ENVIRONMENT: dev
|
|
||||||
RELEASE_STORE_ROOT: /salon-release
|
|
||||||
NACOS_SNAPSHOT_ID: ${{ inputs.snapshot_id }}
|
|
||||||
NACOS_DEV_URLS: ${{ secrets.NACOS_DEV_URLS }}
|
|
||||||
NACOS_DEV_USERNAME: ${{ secrets.NACOS_DEV_USERNAME }}
|
|
||||||
NACOS_DEV_PASSWORD: ${{ secrets.NACOS_DEV_PASSWORD }}
|
|
||||||
AUTO_ROLLBACK: ${{ inputs.auto_rollback }}
|
|
||||||
steps:
|
|
||||||
- name: 检出回退脚本
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
run: |
|
|
||||||
git init .
|
|
||||||
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
||||||
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$GITHUB_SHA"
|
|
||||||
git checkout --detach "$GITHUB_SHA"
|
|
||||||
- name: 恢复并校验 Nacos
|
|
||||||
shell: bash
|
|
||||||
run: AUTO_ROLLBACK=${AUTO_ROLLBACK:-false} node .gitea/scripts/rollback-nacos.mjs
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
name: 回退生产环境 Nacos 配置
|
|
||||||
|
|
||||||
"on":
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
snapshot_id:
|
|
||||||
description: 可选快照 ID,留空使用待回退快照
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
auto_rollback:
|
|
||||||
description: 是否由自动失败流程触发
|
|
||||||
required: false
|
|
||||||
type: boolean
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-prod
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
rollback:
|
|
||||||
runs-on: jayucloud
|
|
||||||
container:
|
|
||||||
options: >-
|
|
||||||
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
|
|
||||||
env:
|
|
||||||
NACOS_ENVIRONMENT: prod
|
|
||||||
RELEASE_STORE_ROOT: /salon-release
|
|
||||||
NACOS_SNAPSHOT_ID: ${{ inputs.snapshot_id }}
|
|
||||||
NACOS_PROD_URLS: ${{ secrets.NACOS_PROD_URLS }}
|
|
||||||
NACOS_PROD_USERNAME: ${{ secrets.NACOS_PROD_USERNAME }}
|
|
||||||
NACOS_PROD_PASSWORD: ${{ secrets.NACOS_PROD_PASSWORD }}
|
|
||||||
NACOS_DR_URLS: ${{ secrets.NACOS_DR_URLS }}
|
|
||||||
NACOS_DR_USERNAME: ${{ secrets.NACOS_DR_USERNAME }}
|
|
||||||
NACOS_DR_PASSWORD: ${{ secrets.NACOS_DR_PASSWORD }}
|
|
||||||
AUTO_ROLLBACK: ${{ inputs.auto_rollback }}
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
steps:
|
|
||||||
- name: 检出回退脚本
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
run: |
|
|
||||||
git init .
|
|
||||||
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
||||||
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$GITHUB_SHA"
|
|
||||||
git checkout --detach "$GITHUB_SHA"
|
|
||||||
- name: 恢复并校验 Nacos
|
|
||||||
shell: bash
|
|
||||||
run: AUTO_ROLLBACK=${AUTO_ROLLBACK:-false} node .gitea/scripts/rollback-nacos.mjs
|
|
||||||
- name: 触发 PROD 应用恢复
|
|
||||||
if: inputs.auto_rollback == true
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
AUTO_ROLLBACK: 'true'
|
|
||||||
run: node .gitea/scripts/dispatch-workflow.mjs prod环境回退上一个版本.yml refs/heads/prod
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
name: 回退测试环境 Nacos 配置
|
|
||||||
|
|
||||||
"on":
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
snapshot_id:
|
|
||||||
description: 可选快照 ID,留空使用待回退快照
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
auto_rollback:
|
|
||||||
description: 是否由自动失败流程触发
|
|
||||||
required: false
|
|
||||||
type: boolean
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-sit
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
rollback:
|
|
||||||
runs-on: jayucloud
|
|
||||||
container:
|
|
||||||
options: >-
|
|
||||||
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
|
|
||||||
env:
|
|
||||||
NACOS_ENVIRONMENT: sit
|
|
||||||
RELEASE_STORE_ROOT: /salon-release
|
|
||||||
NACOS_SNAPSHOT_ID: ${{ inputs.snapshot_id }}
|
|
||||||
NACOS_SIT_URLS: ${{ secrets.NACOS_SIT_URLS }}
|
|
||||||
NACOS_SIT_USERNAME: ${{ secrets.NACOS_SIT_USERNAME }}
|
|
||||||
NACOS_SIT_PASSWORD: ${{ secrets.NACOS_SIT_PASSWORD }}
|
|
||||||
AUTO_ROLLBACK: ${{ inputs.auto_rollback }}
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
steps:
|
|
||||||
- name: 检出回退脚本
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
run: |
|
|
||||||
git init .
|
|
||||||
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
||||||
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$GITHUB_SHA"
|
|
||||||
git checkout --detach "$GITHUB_SHA"
|
|
||||||
- name: 恢复并校验 Nacos
|
|
||||||
shell: bash
|
|
||||||
run: AUTO_ROLLBACK=${AUTO_ROLLBACK:-false} node .gitea/scripts/rollback-nacos.mjs
|
|
||||||
- name: 触发 SIT 应用恢复
|
|
||||||
if: inputs.auto_rollback == true
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
AUTO_ROLLBACK: 'true'
|
|
||||||
run: node .gitea/scripts/dispatch-workflow.mjs sit环境回退上一个版本.yml refs/heads/sit
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
name: 环境分支晋级检查
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request_target:
|
|
||||||
branches:
|
|
||||||
- sit
|
|
||||||
- prod
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
validate-source:
|
|
||||||
name: environment-promotion-source
|
|
||||||
runs-on: jayucloud
|
|
||||||
steps:
|
|
||||||
- name: 校验环境分支晋级链路
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
TARGET_BRANCH: ${{ gitea.base_ref }}
|
|
||||||
SOURCE_BRANCH: ${{ gitea.head_ref }}
|
|
||||||
SOURCE_REPOSITORY: ${{ gitea.event.pull_request.head.repo.full_name }}
|
|
||||||
TARGET_REPOSITORY: ${{ gitea.repository }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
test -n "$TARGET_BRANCH"
|
|
||||||
test -n "$SOURCE_BRANCH"
|
|
||||||
test -n "$SOURCE_REPOSITORY"
|
|
||||||
test -n "$TARGET_REPOSITORY"
|
|
||||||
|
|
||||||
if [[ "$SOURCE_REPOSITORY" != "$TARGET_REPOSITORY" ]]; then
|
|
||||||
echo "拒绝跨仓库环境晋级:$SOURCE_REPOSITORY -> $TARGET_REPOSITORY"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$TARGET_BRANCH:$SOURCE_BRANCH" in
|
|
||||||
sit:dev|prod:sit)
|
|
||||||
echo "允许环境晋级:$SOURCE_BRANCH -> $TARGET_BRANCH"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "拒绝环境晋级:$SOURCE_BRANCH -> $TARGET_BRANCH"
|
|
||||||
echo "允许链路仅为 dev -> sit -> prod"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
name: 自动发布开发环境 Nacos 配置
|
|
||||||
|
|
||||||
"on":
|
|
||||||
push:
|
|
||||||
branches: [dev]
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-dev
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish:
|
|
||||||
runs-on: jayucloud
|
|
||||||
container:
|
|
||||||
options: >-
|
|
||||||
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
|
|
||||||
env:
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
NACOS_ENVIRONMENT: dev
|
|
||||||
RELEASE_STORE_ROOT: /salon-release
|
|
||||||
RELEASE_ENVIRONMENT: dev
|
|
||||||
NACOS_DEV_URLS: ${{ secrets.NACOS_DEV_URLS }}
|
|
||||||
NACOS_DEV_USERNAME: ${{ secrets.NACOS_DEV_USERNAME }}
|
|
||||||
NACOS_DEV_PASSWORD: ${{ secrets.NACOS_DEV_PASSWORD }}
|
|
||||||
steps:
|
|
||||||
- name: 检出提交
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
test -n "$GITEA_TOKEN"
|
|
||||||
git init .
|
|
||||||
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
||||||
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$GITHUB_SHA"
|
|
||||||
git checkout --detach "$GITHUB_SHA"
|
|
||||||
- name: 发布并校验 Nacos
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
trap 'AUTO_ROLLBACK=true RELEASE_ENVIRONMENT=dev node .gitea/scripts/dispatch-workflow.mjs rollback-dev-nacos.yml refs/heads/dev || true' ERR
|
|
||||||
node .gitea/scripts/publish-nacos.mjs
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
name: 自动发布生产环境 Nacos
|
|
||||||
|
|
||||||
"on":
|
|
||||||
push:
|
|
||||||
branches: [prod]
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-prod
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish:
|
|
||||||
runs-on: jayucloud
|
|
||||||
container:
|
|
||||||
options: >-
|
|
||||||
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
|
|
||||||
env:
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
NACOS_ENVIRONMENT: prod
|
|
||||||
RELEASE_STORE_ROOT: /salon-release
|
|
||||||
RELEASE_ENVIRONMENT: prod
|
|
||||||
NACOS_PROD_URLS: ${{ secrets.NACOS_PROD_URLS }}
|
|
||||||
NACOS_PROD_USERNAME: ${{ secrets.NACOS_PROD_USERNAME }}
|
|
||||||
NACOS_PROD_PASSWORD: ${{ secrets.NACOS_PROD_PASSWORD }}
|
|
||||||
NACOS_DR_URLS: ${{ secrets.NACOS_DR_URLS }}
|
|
||||||
NACOS_DR_USERNAME: ${{ secrets.NACOS_DR_USERNAME }}
|
|
||||||
NACOS_DR_PASSWORD: ${{ secrets.NACOS_DR_PASSWORD }}
|
|
||||||
steps:
|
|
||||||
- name: 检出提交
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
git init .
|
|
||||||
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
||||||
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$GITHUB_SHA"
|
|
||||||
git checkout --detach "$GITHUB_SHA"
|
|
||||||
- name: 发布并校验 Nacos
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
trap 'AUTO_ROLLBACK=true RELEASE_ENVIRONMENT=prod node .gitea/scripts/dispatch-workflow.mjs 回退prod环境nacos配置.yml refs/heads/prod || true' ERR
|
|
||||||
node .gitea/scripts/publish-nacos.mjs
|
|
||||||
- name: 触发生产部署
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
DISPATCH_INPUT_RELEASE_SHA: ${{ github.sha }}
|
|
||||||
run: node .gitea/scripts/dispatch-workflow.mjs 自动部署prod环境.yml refs/heads/prod
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
name: 自动发布测试环境 Nacos 配置
|
|
||||||
|
|
||||||
"on":
|
|
||||||
push:
|
|
||||||
branches: [sit]
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-sit
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish:
|
|
||||||
runs-on: jayucloud
|
|
||||||
container:
|
|
||||||
options: >-
|
|
||||||
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
|
|
||||||
env:
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
NACOS_ENVIRONMENT: sit
|
|
||||||
RELEASE_STORE_ROOT: /salon-release
|
|
||||||
RELEASE_ENVIRONMENT: sit
|
|
||||||
NACOS_SIT_URLS: ${{ secrets.NACOS_SIT_URLS }}
|
|
||||||
NACOS_SIT_USERNAME: ${{ secrets.NACOS_SIT_USERNAME }}
|
|
||||||
NACOS_SIT_PASSWORD: ${{ secrets.NACOS_SIT_PASSWORD }}
|
|
||||||
steps:
|
|
||||||
- name: 检出提交
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
git init .
|
|
||||||
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
||||||
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$GITHUB_SHA"
|
|
||||||
git checkout --detach "$GITHUB_SHA"
|
|
||||||
- name: 发布并校验 Nacos
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
trap 'AUTO_ROLLBACK=true RELEASE_ENVIRONMENT=sit node .gitea/scripts/dispatch-workflow.mjs 回退sit环境nacos配置.yml refs/heads/sit || true' ERR
|
|
||||||
node .gitea/scripts/publish-nacos.mjs
|
|
||||||
- name: 触发 SIT 部署
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
DISPATCH_INPUT_RELEASE_SHA: ${{ github.sha }}
|
|
||||||
run: node .gitea/scripts/dispatch-workflow.mjs 自动部署sit环境.yml refs/heads/sit
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
name: 自动部署生产环境
|
|
||||||
|
|
||||||
"on":
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
release_sha:
|
|
||||||
description: 已成功发布 PROD Nacos 的提交 SHA
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-prod
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
runs-on: jayucloud
|
|
||||||
container:
|
|
||||||
options: >-
|
|
||||||
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
|
|
||||||
env:
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
RELEASE_ENVIRONMENT: prod
|
|
||||||
RELEASE_SHA: ${{ inputs.release_sha || github.sha }}
|
|
||||||
RELEASE_STORE_ROOT: /salon-release
|
|
||||||
WEB_TARGET_HOST: 10.66.0.3
|
|
||||||
WEB_TARGET_PORT: 22
|
|
||||||
WEB_TARGET_USER: root
|
|
||||||
WEB_REMOTE_DIR: /opt/jc-salon-frontend
|
|
||||||
SALON_PROD_SSH_PASSWORD: ${{ secrets.SALON_PROD_SSH_PASSWORD }}
|
|
||||||
NACOS_PROD_URLS: ${{ secrets.NACOS_PROD_URLS }}
|
|
||||||
NACOS_PROD_USERNAME: ${{ secrets.NACOS_PROD_USERNAME }}
|
|
||||||
NACOS_PROD_PASSWORD: ${{ secrets.NACOS_PROD_PASSWORD }}
|
|
||||||
NACOS_DR_URLS: ${{ secrets.NACOS_DR_URLS }}
|
|
||||||
NACOS_DR_USERNAME: ${{ secrets.NACOS_DR_USERNAME }}
|
|
||||||
NACOS_DR_PASSWORD: ${{ secrets.NACOS_DR_PASSWORD }}
|
|
||||||
steps:
|
|
||||||
- name: 检出发布提交
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
git init .
|
|
||||||
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
||||||
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$RELEASE_SHA"
|
|
||||||
git checkout --detach "$RELEASE_SHA"
|
|
||||||
- name: 校验 PROD Nacos 发布记录
|
|
||||||
shell: bash
|
|
||||||
run: node .gitea/scripts/assert-nacos-release.mjs
|
|
||||||
- name: 构建并固化 PROD 发布包
|
|
||||||
shell: pwsh
|
|
||||||
env:
|
|
||||||
VITE_API_BASE_URL: https://salon.yunail.art/api
|
|
||||||
VITE_ADMIN_API_BASE_URL: https://salon.yunail.art/admin/api
|
|
||||||
run: ./docs/scripts/deploy-jayucloud-salon-production.ps1 -PackageOnly -SkipTests -SkipDatabaseInit
|
|
||||||
- name: 保存发布包
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
package_dir="/salon-release/packages/prod/${RELEASE_SHA}-${GITHUB_RUN_ID}"
|
|
||||||
mkdir -p "$package_dir"
|
|
||||||
cp -a artifacts/release/. "$package_dir/"
|
|
||||||
echo "PACKAGE_DIRECTORY=$package_dir" >> "$GITHUB_ENV"
|
|
||||||
- name: 安装 SSH 密码工具
|
|
||||||
shell: bash
|
|
||||||
run: apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sshpass
|
|
||||||
- name: 写入 PROD 目标清单
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
mkdir -p "$RUNNER_TEMP/salon-prod"
|
|
||||||
printf '[{"Name":"core01-01","Host":"192.168.10.24","Port":22,"User":"root","Environment":"prod"},{"Name":"core01-02","Host":"192.168.10.25","Port":22,"User":"root","Environment":"prod"},{"Name":"core01-03","Host":"192.168.20.16","Port":22,"User":"root","Environment":"prod"},{"Name":"gateway01-01","Host":"192.168.10.26","Port":22,"User":"root","Environment":"prod"},{"Name":"gateway01-02","Host":"192.168.10.27","Port":22,"User":"root","Environment":"prod"},{"Name":"gateway01-03","Host":"192.168.20.18","Port":22,"User":"root","Environment":"prod"},{"Name":"salon-web","Host":"%s","Port":%s,"User":"%s","Environment":"prod"}]\n' "$WEB_TARGET_HOST" "$WEB_TARGET_PORT" "$WEB_TARGET_USER" > "$RUNNER_TEMP/salon-prod/servers.json"
|
|
||||||
- name: 执行 PROD 部署
|
|
||||||
shell: pwsh
|
|
||||||
run: ./docs/scripts/deploy-jayucloud-salon-production.ps1 -Deploy -SkipDatabaseInit -RequireSystemd -PackageDirectory "$env:PACKAGE_DIRECTORY" -ServerInfoJsonPath "$env:RUNNER_TEMP/salon-prod/servers.json" -SshPassword "$env:SALON_PROD_SSH_PASSWORD" -CoreRemoteAppDir /opt/jc-salon-core -GatewayRemoteAppDir /opt/jc-salon-gateway -CorePattern '^core01-' -GatewayPattern '^gateway01-' -CoreServiceName jc-salon-core -GatewayServiceName jc-salon-gateway -WebTargetName salon-web -WebRemoteDir "$env:WEB_REMOTE_DIR" -PublicBaseUrl https://salon.yunail.art
|
|
||||||
- name: 记录成功部署
|
|
||||||
shell: bash
|
|
||||||
run: node .gitea/scripts/record-deploy.mjs
|
|
||||||
- name: 部署失败自动回退
|
|
||||||
if: failure()
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
AUTO_ROLLBACK: 'true'
|
|
||||||
run: node .gitea/scripts/dispatch-workflow.mjs prod环境回退上一个版本.yml refs/heads/prod
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
name: 自动部署测试环境
|
|
||||||
|
|
||||||
"on":
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
release_sha:
|
|
||||||
description: 已成功发布 SIT Nacos 的提交 SHA
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-sit
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
runs-on: jayucloud
|
|
||||||
container:
|
|
||||||
options: >-
|
|
||||||
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
|
|
||||||
env:
|
|
||||||
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
||||||
RELEASE_ENVIRONMENT: sit
|
|
||||||
RELEASE_SHA: ${{ inputs.release_sha || github.sha }}
|
|
||||||
RELEASE_STORE_ROOT: /salon-release
|
|
||||||
WEB_TARGET_HOST: 10.66.0.3
|
|
||||||
WEB_TARGET_PORT: 22
|
|
||||||
WEB_TARGET_USER: root
|
|
||||||
WEB_REMOTE_DIR: /opt/jc-salon-frontend-sit
|
|
||||||
SALON_PROD_SSH_PASSWORD: ${{ secrets.SALON_PROD_SSH_PASSWORD }}
|
|
||||||
NACOS_SIT_URLS: ${{ secrets.NACOS_SIT_URLS }}
|
|
||||||
NACOS_SIT_USERNAME: ${{ secrets.NACOS_SIT_USERNAME }}
|
|
||||||
NACOS_SIT_PASSWORD: ${{ secrets.NACOS_SIT_PASSWORD }}
|
|
||||||
steps:
|
|
||||||
- name: 检出发布提交
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
git init .
|
|
||||||
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
||||||
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$RELEASE_SHA"
|
|
||||||
git checkout --detach "$RELEASE_SHA"
|
|
||||||
- name: 校验 SIT Nacos 发布记录
|
|
||||||
shell: bash
|
|
||||||
run: node .gitea/scripts/assert-nacos-release.mjs
|
|
||||||
- name: 构建 SIT 发布包
|
|
||||||
shell: pwsh
|
|
||||||
env:
|
|
||||||
VITE_API_BASE_URL: https://sit.yunail.art/api
|
|
||||||
VITE_ADMIN_API_BASE_URL: https://sit.yunail.art/admin/api
|
|
||||||
run: ./docs/scripts/deploy-jayucloud-salon-production.ps1 -PackageOnly -SkipTests -SkipDatabaseInit
|
|
||||||
- name: 持久化已校验发布包
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
package_dir="/salon-release/packages/sit/${RELEASE_SHA}-${GITHUB_RUN_ID}"
|
|
||||||
mkdir -p "$package_dir"
|
|
||||||
cp -a artifacts/release/. "$package_dir/"
|
|
||||||
echo "PACKAGE_DIRECTORY=$package_dir" >> "$GITHUB_ENV"
|
|
||||||
- name: 安装 SSH 密码工具
|
|
||||||
shell: bash
|
|
||||||
run: apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sshpass
|
|
||||||
- name: 写入 SIT 目标清单
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
mkdir -p "$RUNNER_TEMP/salon-sit"
|
|
||||||
printf '[{"Name":"sit-app01","Host":"192.168.10.15","Port":22,"User":"root","Purpose":"Salon SIT Core/Gateway","Environment":"sit"},{"Name":"salon-web-sit","Host":"%s","Port":%s,"User":"%s","Purpose":"Salon SIT NGINX","Environment":"sit"}]\n' "$WEB_TARGET_HOST" "$WEB_TARGET_PORT" "$WEB_TARGET_USER" > "$RUNNER_TEMP/salon-sit/servers.json"
|
|
||||||
- name: 执行 SIT 部署
|
|
||||||
shell: pwsh
|
|
||||||
run: ./docs/scripts/deploy-jayucloud-salon-production.ps1 -Deploy -SkipDatabaseInit -AllowSitTarget -RequireSystemd -PackageDirectory "$env:PACKAGE_DIRECTORY" -ServerInfoJsonPath "$env:RUNNER_TEMP/salon-sit/servers.json" -SshPassword "$env:SALON_PROD_SSH_PASSWORD" -CoreRemoteAppDir /opt/jc-salon-core-sit -GatewayRemoteAppDir /opt/jc-salon-gateway-sit -CorePattern '^sit-app01$' -GatewayPattern '^sit-app01$' -CoreServiceName jc-salon-core-sit -GatewayServiceName jc-salon-gateway-sit -CoreHealthPort 181 -GatewayHealthPort 180 -WebTargetName salon-web-sit -WebRemoteDir "$env:WEB_REMOTE_DIR" -PublicBaseUrl https://sit.yunail.art
|
|
||||||
- name: 记录成功部署
|
|
||||||
shell: bash
|
|
||||||
run: node .gitea/scripts/record-deploy.mjs
|
|
||||||
- name: 部署失败自动回退
|
|
||||||
if: failure()
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
AUTO_ROLLBACK: 'true'
|
|
||||||
run: node .gitea/scripts/dispatch-workflow.mjs sit环境回退上一个版本.yml refs/heads/sit
|
|
||||||
@@ -5,12 +5,6 @@
|
|||||||
# Log file
|
# Log file
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
# Full-regression database backups may contain development user data.
|
|
||||||
artifacts/full-regression/*backup*.sql
|
|
||||||
|
|
||||||
# Local Codex agent skill mirrors; canonical project skills live under .claude/.
|
|
||||||
.agents/
|
|
||||||
|
|
||||||
# BlueJ files
|
# BlueJ files
|
||||||
*.ctxt
|
*.ctxt
|
||||||
|
|
||||||
@@ -40,10 +34,8 @@ docs/_book
|
|||||||
|
|
||||||
# TODO: where does this rule come from?
|
# TODO: where does this rule come from?
|
||||||
test/
|
test/
|
||||||
!FD-Core/src/test/
|
!YumiNail-Core/src/test/
|
||||||
!FD-Core/src/test/**
|
!YumiNail-Core/src/test/**
|
||||||
!FD-Gateway/src/test/
|
|
||||||
!FD-Gateway/src/test/**
|
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
@@ -268,17 +260,10 @@ jspm_packages/
|
|||||||
|
|
||||||
# Mini program local overrides
|
# Mini program local overrides
|
||||||
WeChatProgram/utils/config.local.js
|
WeChatProgram/utils/config.local.js
|
||||||
JayuCloudArtList-Admin-Program/utils/config.local.js
|
YumiNail-Admin-Program/utils/config.local.js
|
||||||
FM-Wechat-Fronted/utils/config.local.js
|
|
||||||
|
|
||||||
# 本地敏感服务器信息
|
|
||||||
docx/服务器信息.xlsx
|
|
||||||
docx/生产服务器信息.xlsx
|
|
||||||
|
|
||||||
# Local release/test artifacts
|
# Local release/test artifacts
|
||||||
release-packages/
|
release-packages/
|
||||||
/.codex-tmp/
|
|
||||||
/tmp/
|
|
||||||
artifacts/full-acceptance-*/
|
artifacts/full-acceptance-*/
|
||||||
artifacts/release/
|
artifacts/release/
|
||||||
.codex-run/
|
.codex-run/
|
||||||
@@ -403,4 +388,3 @@ m2repo/
|
|||||||
|
|
||||||
/docs/product/
|
/docs/product/
|
||||||
WeChatProgram/project.private.config.json
|
WeChatProgram/project.private.config.json
|
||||||
/.idea/
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Ignored default folder with query files
|
||||||
|
/queries/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile default="true" name="Default" enabled="true" />
|
||||||
|
<profile name="Annotation profile for YumiNail-Core" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<processorPath useClasspath="false">
|
||||||
|
<entry name="D:/apache-maven-3.9.9/repository/nailart/org/projectlombok/lombok/1.18.32/lombok-1.18.32.jar" />
|
||||||
|
</processorPath>
|
||||||
|
<module name="YumiNail-Core" />
|
||||||
|
</profile>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="YumiNail-Gateway" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
<component name="JavacSettings">
|
||||||
|
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||||
|
<module name="YumiNail-Core" options="-parameters" />
|
||||||
|
<module name="YumiNail-Gateway" options="-parameters" />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/YumiNail-Core/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/YumiNail-Gateway/src/main/java" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://maven.aliyun.com/repository/public" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/YumiNail-Core/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/YumiNail-Gateway/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/xiaowang.iml" filepath="$PROJECT_DIR$/.idea/xiaowang.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
@@ -1,33 +1,33 @@
|
|||||||
<!-- gitnexus:start -->
|
<!-- gitnexus:start -->
|
||||||
# GitNexus — Code Intelligence
|
# GitNexus — Code Intelligence
|
||||||
|
|
||||||
This project is indexed by GitNexus as **JayuCloud** (22596 symbols, 47343 relationships, 300 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
|
This project is indexed by GitNexus as **xiaowang** (17889 symbols, 35678 relationships, 300 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
|
||||||
|
|
||||||
> Index stale? Run `node .gitnexus/run.cjs analyze` from the project root — it auto-selects an available runner. No `.gitnexus/run.cjs` yet? `npx gitnexus analyze` (npm 11 crash → `npm i -g gitnexus`; #1939).
|
> If any GitNexus tool warns the index is stale, run `npx gitnexus analyze` in terminal first.
|
||||||
|
|
||||||
## Always Do
|
## Always Do
|
||||||
|
|
||||||
- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run `impact({target: "symbolName", direction: "upstream"})` and report the blast radius (direct callers, affected processes, risk level) to the user.
|
- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run `gitnexus_impact({target: "symbolName", direction: "upstream"})` and report the blast radius (direct callers, affected processes, risk level) to the user.
|
||||||
- **MUST run `detect_changes()` before committing** to verify your changes only affect expected symbols and execution flows. For regression review, compare against the default branch: `detect_changes({scope: "compare", base_ref: "master"})`.
|
- **MUST run `gitnexus_detect_changes()` before committing** to verify your changes only affect expected symbols and execution flows.
|
||||||
- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
|
- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
|
||||||
- When exploring unfamiliar code, use `query({query: "concept"})` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance.
|
- When exploring unfamiliar code, use `gitnexus_query({query: "concept"})` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance.
|
||||||
- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use `context({name: "symbolName"})`.
|
- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use `gitnexus_context({name: "symbolName"})`.
|
||||||
|
|
||||||
## Never Do
|
## Never Do
|
||||||
|
|
||||||
- NEVER edit a function, class, or method without first running `impact` on it.
|
- NEVER edit a function, class, or method without first running `gitnexus_impact` on it.
|
||||||
- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
|
- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
|
||||||
- NEVER rename symbols with find-and-replace — use `rename` which understands the call graph.
|
- NEVER rename symbols with find-and-replace — use `gitnexus_rename` which understands the call graph.
|
||||||
- NEVER commit changes without running `detect_changes()` to check affected scope.
|
- NEVER commit changes without running `gitnexus_detect_changes()` to check affected scope.
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
|
||||||
| Resource | Use for |
|
| Resource | Use for |
|
||||||
|----------|---------|
|
|----------|---------|
|
||||||
| `gitnexus://repo/JayuCloud/context` | Codebase overview, check index freshness |
|
| `gitnexus://repo/xiaowang/context` | Codebase overview, check index freshness |
|
||||||
| `gitnexus://repo/JayuCloud/clusters` | All functional areas |
|
| `gitnexus://repo/xiaowang/clusters` | All functional areas |
|
||||||
| `gitnexus://repo/JayuCloud/processes` | All execution flows |
|
| `gitnexus://repo/xiaowang/processes` | All execution flows |
|
||||||
| `gitnexus://repo/JayuCloud/process/{name}` | Step-by-step execution trace |
|
| `gitnexus://repo/xiaowang/process/{name}` | Step-by-step execution trace |
|
||||||
|
|
||||||
## CLI
|
## CLI
|
||||||
|
|
||||||
@@ -42,16 +42,6 @@ This project is indexed by GitNexus as **JayuCloud** (22596 symbols, 47343 relat
|
|||||||
|
|
||||||
<!-- gitnexus:end -->
|
<!-- gitnexus:end -->
|
||||||
|
|
||||||
## Project Workflow Rules
|
|
||||||
|
|
||||||
- 每次任务中发现的问题、原因和处理方式都需要记录下来,并在后续相关任务中回顾,避免重复发生。
|
|
||||||
- 后端修改如果涉及 SQL,默认新增版本变更 SQL;只有负责人明确要求重整初始化基线时,才将已存在的变更合并到初始化 SQL。
|
|
||||||
- 版本变更 SQL 文件名必须使用中文,体现功能和日期,并且 SQL 内容必须是完整可执行脚本。
|
|
||||||
- 如果修改涉及配置,必须提供说明文档;说明文档同样按 SQL 文件命名规则使用中文命名、体现功能和日期,并放在 `scripts/` 目录下。
|
|
||||||
- 当前代码、脚本、配置、SQL 和文档已固定为 `0.0.1` 基线;两个端侧初始化 SQL 仅作为空库首次初始化入口,后续 SQL 变更默认使用版本迭代文件,负责人明确要求整合基线时除外。
|
|
||||||
- 后续涉及脚本、配置、SQL 的任务,必须优先阅读 `scripts/0.0.1版本基线与后续迭代规则_20260628.md`,并在任务记录中写明新增或调整的版本化文件。
|
|
||||||
- 每次修改代码或者完成任务后,必须整理本次任务相关改动并创建 git 提交;提交信息必须使用中文。
|
|
||||||
|
|
||||||
## Browser MCP Preference
|
## Browser MCP Preference
|
||||||
|
|
||||||
- For any browser-related operation, including opening, navigating, clicking, typing, inspecting pages/devtools, taking screenshots, testing pages, or automating local/remote web targets, use the `edgedev` MCP server first.
|
- For any browser-related operation, including opening, navigating, clicking, typing, inspecting pages/devtools, taking screenshots, testing pages, or automating local/remote web targets, use the `edgedev` MCP server first.
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
<!-- gitnexus:start -->
|
<!-- gitnexus:start -->
|
||||||
# GitNexus — Code Intelligence
|
# GitNexus — Code Intelligence
|
||||||
|
|
||||||
This project is indexed by GitNexus as **JayuCloud** (22596 symbols, 47343 relationships, 300 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
|
This project is indexed by GitNexus as **xiaowang** (17889 symbols, 35678 relationships, 300 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
|
||||||
|
|
||||||
> Index stale? Run `node .gitnexus/run.cjs analyze` from the project root — it auto-selects an available runner. No `.gitnexus/run.cjs` yet? `npx gitnexus analyze` (npm 11 crash → `npm i -g gitnexus`; #1939).
|
> If any GitNexus tool warns the index is stale, run `npx gitnexus analyze` in terminal first.
|
||||||
|
|
||||||
## Always Do
|
## Always Do
|
||||||
|
|
||||||
- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run `impact({target: "symbolName", direction: "upstream"})` and report the blast radius (direct callers, affected processes, risk level) to the user.
|
- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run `gitnexus_impact({target: "symbolName", direction: "upstream"})` and report the blast radius (direct callers, affected processes, risk level) to the user.
|
||||||
- **MUST run `detect_changes()` before committing** to verify your changes only affect expected symbols and execution flows. For regression review, compare against the default branch: `detect_changes({scope: "compare", base_ref: "master"})`.
|
- **MUST run `gitnexus_detect_changes()` before committing** to verify your changes only affect expected symbols and execution flows.
|
||||||
- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
|
- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
|
||||||
- When exploring unfamiliar code, use `query({query: "concept"})` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance.
|
- When exploring unfamiliar code, use `gitnexus_query({query: "concept"})` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance.
|
||||||
- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use `context({name: "symbolName"})`.
|
- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use `gitnexus_context({name: "symbolName"})`.
|
||||||
|
|
||||||
## Never Do
|
## Never Do
|
||||||
|
|
||||||
- NEVER edit a function, class, or method without first running `impact` on it.
|
- NEVER edit a function, class, or method without first running `gitnexus_impact` on it.
|
||||||
- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
|
- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
|
||||||
- NEVER rename symbols with find-and-replace — use `rename` which understands the call graph.
|
- NEVER rename symbols with find-and-replace — use `gitnexus_rename` which understands the call graph.
|
||||||
- NEVER commit changes without running `detect_changes()` to check affected scope.
|
- NEVER commit changes without running `gitnexus_detect_changes()` to check affected scope.
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
|
||||||
| Resource | Use for |
|
| Resource | Use for |
|
||||||
|----------|---------|
|
|----------|---------|
|
||||||
| `gitnexus://repo/JayuCloud/context` | Codebase overview, check index freshness |
|
| `gitnexus://repo/xiaowang/context` | Codebase overview, check index freshness |
|
||||||
| `gitnexus://repo/JayuCloud/clusters` | All functional areas |
|
| `gitnexus://repo/xiaowang/clusters` | All functional areas |
|
||||||
| `gitnexus://repo/JayuCloud/processes` | All execution flows |
|
| `gitnexus://repo/xiaowang/processes` | All execution flows |
|
||||||
| `gitnexus://repo/JayuCloud/process/{name}` | Step-by-step execution trace |
|
| `gitnexus://repo/xiaowang/process/{name}` | Step-by-step execution trace |
|
||||||
|
|
||||||
## CLI
|
## CLI
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
const request = require('../utils/request')
|
||||||
|
const { API_DOMAIN } = require('../utils/config')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
login(data) {
|
||||||
|
return request({
|
||||||
|
url: '/auth/login',
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
register(data) {
|
||||||
|
return request({
|
||||||
|
url: '/auth/register',
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
sendCode(phone) {
|
||||||
|
return request({
|
||||||
|
url: '/user/send-verification-code',
|
||||||
|
method: 'POST',
|
||||||
|
params: {
|
||||||
|
__baseUrl: API_DOMAIN
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
phone,
|
||||||
|
sceneCode: 'PLANNING_MANAGER_REGISTER'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
logout() {
|
||||||
|
return request({
|
||||||
|
url: '/auth/logout',
|
||||||
|
method: 'POST'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
const request = require('../utils/request')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
list(params) {
|
||||||
|
return request({
|
||||||
|
url: '/user/list',
|
||||||
|
params: {
|
||||||
|
type: 0,
|
||||||
|
hasOrder: true,
|
||||||
|
...params
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
detail(id) {
|
||||||
|
return request({
|
||||||
|
url: `/user/detail/${id}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
const request = require('../utils/request')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
list(params) {
|
||||||
|
return request({
|
||||||
|
url: '/nail-artist/list',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
detail(userId) {
|
||||||
|
return request({
|
||||||
|
url: `/nail-artist/get/${userId}`
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
save(data) {
|
||||||
|
return request({
|
||||||
|
url: '/nail-artist/save',
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
schedules(params) {
|
||||||
|
return request({
|
||||||
|
url: '/artist-schedule/list',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
saveSchedule(data) {
|
||||||
|
return request({
|
||||||
|
url: '/artist-schedule/save',
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
const request = require('../utils/request')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
calendar(params) {
|
||||||
|
return request({
|
||||||
|
url: '/planning/calendar',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
createAppointment(data) {
|
||||||
|
return request({
|
||||||
|
url: '/planning/appointments',
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
appointment(orderItemId) {
|
||||||
|
return request({
|
||||||
|
url: `/planning/appointments/${orderItemId}`
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
moveAppointment(orderItemId, data) {
|
||||||
|
return request({
|
||||||
|
url: `/planning/appointments/${orderItemId}/time-artist`,
|
||||||
|
method: 'PUT',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
updateStatus(orderId, status) {
|
||||||
|
return request({
|
||||||
|
url: `/planning/appointments/${orderId}/status`,
|
||||||
|
method: 'PUT',
|
||||||
|
data: { status }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ const request = require('../utils/request')
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
list(params) {
|
list(params) {
|
||||||
return request({
|
return request({
|
||||||
url: '/manager/products',
|
url: '/product/list',
|
||||||
params
|
params
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
const request = require('../utils/request')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
settings() {
|
||||||
|
return request({
|
||||||
|
url: '/shops/current'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
saveSettings(data) {
|
||||||
|
return request({
|
||||||
|
url: '/shops/current',
|
||||||
|
method: 'PUT',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
exportData(params) {
|
||||||
|
return request({
|
||||||
|
url: '/export',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
const auth = require('./utils/auth')
|
||||||
|
|
||||||
|
App({
|
||||||
|
globalData: {
|
||||||
|
appName: '指尖管理师',
|
||||||
|
shopName: 'Yumi Nail',
|
||||||
|
userInfo: null
|
||||||
|
},
|
||||||
|
|
||||||
|
onLaunch() {
|
||||||
|
this.bootstrapSession()
|
||||||
|
},
|
||||||
|
|
||||||
|
bootstrapSession() {
|
||||||
|
const session = auth.getSession()
|
||||||
|
this.globalData.userInfo = session.userInfo || null
|
||||||
|
if (session.shopName) {
|
||||||
|
this.globalData.shopName = session.shopName
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
setSession(session) {
|
||||||
|
auth.setSession(session)
|
||||||
|
this.bootstrapSession()
|
||||||
|
},
|
||||||
|
|
||||||
|
clearSession() {
|
||||||
|
auth.clearSession()
|
||||||
|
this.globalData.userInfo = null
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
{
|
||||||
|
"pages": [
|
||||||
|
"pages/login/index",
|
||||||
|
"pages/register/index",
|
||||||
|
"pages/planning/index",
|
||||||
|
"pages/appointment-form/index",
|
||||||
|
"pages/appointment-detail/index",
|
||||||
|
"pages/artist-transfer/index",
|
||||||
|
"pages/customers/index",
|
||||||
|
"pages/customer-detail/index",
|
||||||
|
"pages/employees/index",
|
||||||
|
"pages/employee-detail/index",
|
||||||
|
"pages/schedule-setting/index",
|
||||||
|
"pages/leave-management/index",
|
||||||
|
"pages/color-setting/index",
|
||||||
|
"pages/employee-orders/index",
|
||||||
|
"pages/profile/index",
|
||||||
|
"pages/shop-settings/index",
|
||||||
|
"pages/export/index",
|
||||||
|
"pages/password/index",
|
||||||
|
"pages/about/index"
|
||||||
|
],
|
||||||
|
"window": {
|
||||||
|
"navigationBarTitleText": "指尖管理师",
|
||||||
|
"navigationBarBackgroundColor": "#F8F5EF",
|
||||||
|
"navigationBarTextStyle": "black",
|
||||||
|
"backgroundColor": "#F8F5EF",
|
||||||
|
"backgroundTextStyle": "dark"
|
||||||
|
},
|
||||||
|
"tabBar": {
|
||||||
|
"color": "#8B8680",
|
||||||
|
"selectedColor": "#2F6F62",
|
||||||
|
"backgroundColor": "#FFFDF8",
|
||||||
|
"borderStyle": "white",
|
||||||
|
"list": [
|
||||||
|
{
|
||||||
|
"pagePath": "pages/planning/index",
|
||||||
|
"text": "规划",
|
||||||
|
"iconPath": "assets/tabbar/planning.png",
|
||||||
|
"selectedIconPath": "assets/tabbar/planning-active.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pagePath": "pages/customers/index",
|
||||||
|
"text": "客户",
|
||||||
|
"iconPath": "assets/tabbar/customers.png",
|
||||||
|
"selectedIconPath": "assets/tabbar/customers-active.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pagePath": "pages/employees/index",
|
||||||
|
"text": "员工",
|
||||||
|
"iconPath": "assets/tabbar/employees.png",
|
||||||
|
"selectedIconPath": "assets/tabbar/employees-active.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pagePath": "pages/profile/index",
|
||||||
|
"text": "我的",
|
||||||
|
"iconPath": "assets/tabbar/profile.png",
|
||||||
|
"selectedIconPath": "assets/tabbar/profile-active.png"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"style": "v2",
|
||||||
|
"sitemapLocation": "sitemap.json"
|
||||||
|
}
|
||||||
@@ -0,0 +1,279 @@
|
|||||||
|
page {
|
||||||
|
min-height: 100%;
|
||||||
|
background: #f8f5ef;
|
||||||
|
color: #26231f;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
view,
|
||||||
|
text,
|
||||||
|
button,
|
||||||
|
input,
|
||||||
|
textarea,
|
||||||
|
picker,
|
||||||
|
scroll-view {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
min-width: 0;
|
||||||
|
border-radius: 0;
|
||||||
|
background: transparent;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
button::after {
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page {
|
||||||
|
min-height: 100vh;
|
||||||
|
padding: 22rpx 24rpx 140rpx;
|
||||||
|
background: #f8f5ef;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page.no-tab {
|
||||||
|
padding-bottom: 196rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
border: 1rpx solid rgba(50, 43, 34, 0.06);
|
||||||
|
border-radius: 12px;
|
||||||
|
background: #fffdf8;
|
||||||
|
box-shadow: 0 10rpx 28rpx rgba(58, 48, 34, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section {
|
||||||
|
margin-top: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
margin: 4rpx 4rpx 16rpx;
|
||||||
|
color: #4c4740;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.between {
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.muted {
|
||||||
|
color: #9d968e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
min-height: 40rpx;
|
||||||
|
padding: 0 16rpx;
|
||||||
|
border-radius: 999rpx;
|
||||||
|
background: #f0ece5;
|
||||||
|
color: #6d675f;
|
||||||
|
font-size: 22rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary-btn,
|
||||||
|
.secondary-btn,
|
||||||
|
.text-btn,
|
||||||
|
.danger-btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 76rpx;
|
||||||
|
border-radius: 12px;
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary-btn,
|
||||||
|
.secondary-btn,
|
||||||
|
.danger-btn {
|
||||||
|
min-width: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary-btn {
|
||||||
|
background: #6f8f83;
|
||||||
|
color: #fffdf8;
|
||||||
|
box-shadow: 0 12rpx 24rpx rgba(111, 143, 131, 0.22);
|
||||||
|
}
|
||||||
|
|
||||||
|
.secondary-btn {
|
||||||
|
border: 1rpx solid #d8d1c8;
|
||||||
|
background: #fffdf8;
|
||||||
|
color: #514b44;
|
||||||
|
}
|
||||||
|
|
||||||
|
.danger-btn {
|
||||||
|
background: #d98d8d;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-btn {
|
||||||
|
width: auto;
|
||||||
|
min-width: 0;
|
||||||
|
max-width: none;
|
||||||
|
min-height: 56rpx;
|
||||||
|
color: #6f8f83;
|
||||||
|
font-size: 26rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-btn,
|
||||||
|
.small-action {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 112rpx;
|
||||||
|
min-width: 112rpx;
|
||||||
|
max-width: 112rpx;
|
||||||
|
height: 56rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
border-radius: 999rpx;
|
||||||
|
background: #e5eee9;
|
||||||
|
color: #55786d;
|
||||||
|
font-size: 24rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.small-action {
|
||||||
|
width: 112rpx;
|
||||||
|
min-width: 104rpx;
|
||||||
|
max-width: 112rpx;
|
||||||
|
height: 52rpx;
|
||||||
|
background: #f0ece5;
|
||||||
|
color: #5f5951;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 64rpx;
|
||||||
|
min-width: 64rpx;
|
||||||
|
max-width: 64rpx;
|
||||||
|
height: 64rpx;
|
||||||
|
min-height: 64rpx;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #fffdf8;
|
||||||
|
color: #4e4942;
|
||||||
|
box-shadow: 0 6rpx 14rpx rgba(58, 48, 34, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-card {
|
||||||
|
padding: 8rpx 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-height: 108rpx;
|
||||||
|
border-bottom: 1rpx solid #eee8df;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field:last-child {
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-label {
|
||||||
|
width: 180rpx;
|
||||||
|
color: #625c55;
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field input,
|
||||||
|
.field textarea,
|
||||||
|
.field-value {
|
||||||
|
flex: 1;
|
||||||
|
color: #27231f;
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field textarea {
|
||||||
|
min-height: 140rpx;
|
||||||
|
padding: 34rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fixed-bottom {
|
||||||
|
position: fixed;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 20;
|
||||||
|
padding: 14rpx 24rpx calc(14rpx + env(safe-area-inset-bottom));
|
||||||
|
background: rgba(248, 245, 239, 0.94);
|
||||||
|
backdrop-filter: blur(18rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
.fab {
|
||||||
|
position: fixed;
|
||||||
|
right: 28rpx;
|
||||||
|
bottom: calc(100rpx + env(safe-area-inset-bottom));
|
||||||
|
z-index: 18;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 84rpx;
|
||||||
|
min-width: 84rpx;
|
||||||
|
max-width: 84rpx;
|
||||||
|
height: 84rpx;
|
||||||
|
min-height: 84rpx;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #6f8f83;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 46rpx;
|
||||||
|
font-weight: 300;
|
||||||
|
line-height: 84rpx;
|
||||||
|
box-shadow: 0 12rpx 26rpx rgba(111, 143, 131, 0.24);
|
||||||
|
}
|
||||||
|
|
||||||
|
.list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 18rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-card {
|
||||||
|
padding: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty {
|
||||||
|
padding: 56rpx 24rpx;
|
||||||
|
color: #a39b91;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12rpx;
|
||||||
|
margin: 18rpx 0;
|
||||||
|
padding: 22rpx;
|
||||||
|
border-color: rgba(191, 111, 104, 0.22);
|
||||||
|
background: #fff8f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-title {
|
||||||
|
color: #7f4540;
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-desc {
|
||||||
|
color: #9b6a62;
|
||||||
|
font-size: 24rpx;
|
||||||
|
line-height: 1.45;
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 448 B After Width: | Height: | Size: 448 B |
|
Before Width: | Height: | Size: 306 B After Width: | Height: | Size: 306 B |
|
Before Width: | Height: | Size: 453 B After Width: | Height: | Size: 453 B |
|
Before Width: | Height: | Size: 290 B After Width: | Height: | Size: 290 B |
|
Before Width: | Height: | Size: 397 B After Width: | Height: | Size: 397 B |
|
Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B |
|
Before Width: | Height: | Size: 434 B After Width: | Height: | Size: 434 B |
|
Before Width: | Height: | Size: 285 B After Width: | Height: | Size: 285 B |
@@ -0,0 +1 @@
|
|||||||
|
Page({})
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<view class="page no-tab about-page">
|
||||||
|
<view class="brand-card card">
|
||||||
|
<view class="logo">指</view>
|
||||||
|
<text class="name">指尖管理师</text>
|
||||||
|
<text class="desc">专为美甲店店长设计的预约排班日历子系统</text>
|
||||||
|
</view>
|
||||||
|
<view class="card about-list">
|
||||||
|
<view class="row between"><text>版本</text><text class="muted">1.0.0</text></view>
|
||||||
|
<view class="row between"><text>定位</text><text class="muted">规划 / 客户 / 员工 / 我的</text></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
.about-page {
|
||||||
|
padding-top: 80rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: 52rpx 28rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 112rpx;
|
||||||
|
height: 112rpx;
|
||||||
|
border-radius: 30rpx;
|
||||||
|
background: #6f8f83;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 52rpx;
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name {
|
||||||
|
margin-top: 22rpx;
|
||||||
|
font-size: 38rpx;
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desc {
|
||||||
|
margin-top: 12rpx;
|
||||||
|
color: #90887e;
|
||||||
|
font-size: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.about-list {
|
||||||
|
margin-top: 20rpx;
|
||||||
|
padding: 24rpx;
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
const planningApi = require('../../api/planning')
|
||||||
|
const config = require('../../utils/config')
|
||||||
|
const mock = require('../../utils/mock')
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
id: '',
|
||||||
|
appointment: {},
|
||||||
|
avatarText: '',
|
||||||
|
timeText: '',
|
||||||
|
loadError: false,
|
||||||
|
errorMessage: ''
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(options = {}) {
|
||||||
|
this.setData({ id: options.id || '' })
|
||||||
|
this.loadDetail()
|
||||||
|
},
|
||||||
|
|
||||||
|
async loadDetail() {
|
||||||
|
this.setData({ loadError: false, errorMessage: '' })
|
||||||
|
try {
|
||||||
|
const appointment = await planningApi.appointment(this.data.id)
|
||||||
|
this.applyAppointment(appointment)
|
||||||
|
} catch (error) {
|
||||||
|
if (config.USE_DEV_MOCK_DATA) {
|
||||||
|
const demo = mock.buildCalendar(new Date()).appointments[0]
|
||||||
|
this.applyAppointment(demo)
|
||||||
|
} else {
|
||||||
|
this.setData({
|
||||||
|
appointment: {},
|
||||||
|
avatarText: '',
|
||||||
|
timeText: '',
|
||||||
|
loadError: true,
|
||||||
|
errorMessage: error.message || '预约详情加载失败,请检查服务连接后重试'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
applyAppointment(appointment) {
|
||||||
|
this.setData({
|
||||||
|
appointment,
|
||||||
|
avatarText: String(appointment.customerName || '客').slice(0, 1),
|
||||||
|
timeText: `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}`,
|
||||||
|
loadError: false,
|
||||||
|
errorMessage: ''
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateStatus(status) {
|
||||||
|
if (!this.data.appointment.orderId) {
|
||||||
|
wx.showToast({ title: '预约数据未加载', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await planningApi.updateStatus(this.data.appointment.orderId, status)
|
||||||
|
wx.showToast({ title: '已更新' })
|
||||||
|
this.loadDetail()
|
||||||
|
} catch (error) {
|
||||||
|
wx.showToast({ title: error.message || '操作失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
confirm() {
|
||||||
|
this.updateStatus(1)
|
||||||
|
},
|
||||||
|
|
||||||
|
complete() {
|
||||||
|
this.updateStatus(2)
|
||||||
|
},
|
||||||
|
|
||||||
|
cancel() {
|
||||||
|
this.updateStatus(3)
|
||||||
|
},
|
||||||
|
|
||||||
|
goTransfer() {
|
||||||
|
wx.navigateTo({ url: `/pages/artist-transfer/index?id=${this.data.id}` })
|
||||||
|
},
|
||||||
|
|
||||||
|
back() {
|
||||||
|
wx.navigateBack()
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<view class="page no-tab">
|
||||||
|
<view wx:if="{{loadError}}" class="card error-card">
|
||||||
|
<text class="error-title">数据加载失败</text>
|
||||||
|
<text class="error-desc">{{errorMessage}}</text>
|
||||||
|
<button class="compact-btn" bindtap="loadDetail">重试</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<block wx:else>
|
||||||
|
<view class="card detail-card">
|
||||||
|
<view class="detail-head">
|
||||||
|
<view class="detail-person">
|
||||||
|
<view class="avatar">{{avatarText}}</view>
|
||||||
|
<view>
|
||||||
|
<text class="customer">{{appointment.customerName}}</text>
|
||||||
|
<text class="phone">{{appointment.customerPhone}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="detail-actions">
|
||||||
|
<text class="tag">{{appointment.statusText}}</text>
|
||||||
|
<button class="small-action" bindtap="goTransfer">改派</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="detail-grid">
|
||||||
|
<view>
|
||||||
|
<text class="label">项目</text>
|
||||||
|
<text class="value">{{appointment.productTitle}}</text>
|
||||||
|
</view>
|
||||||
|
<view>
|
||||||
|
<text class="label">美甲师</text>
|
||||||
|
<text class="value">{{appointment.artistName}}</text>
|
||||||
|
</view>
|
||||||
|
<view>
|
||||||
|
<text class="label">时间</text>
|
||||||
|
<text class="value">{{timeText}}</text>
|
||||||
|
</view>
|
||||||
|
<view>
|
||||||
|
<text class="label">时长</text>
|
||||||
|
<text class="value">{{appointment.durationMinutes}}分钟</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="section">
|
||||||
|
<view class="section-title">备注</view>
|
||||||
|
<view class="card note-card">{{appointment.remark || '暂无备注'}}</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="fixed-bottom action-row">
|
||||||
|
<button class="secondary-btn" bindtap="confirm">确认</button>
|
||||||
|
<button class="primary-btn" bindtap="complete">完成</button>
|
||||||
|
<button class="danger-btn" bindtap="cancel">取消</button>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
.detail-card {
|
||||||
|
padding: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 18rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-person {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
gap: 18rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 82rpx;
|
||||||
|
height: 82rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #e5eee9;
|
||||||
|
color: #5d8175;
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer,
|
||||||
|
.phone {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer {
|
||||||
|
color: #24211d;
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phone {
|
||||||
|
margin-top: 6rpx;
|
||||||
|
color: #928a81;
|
||||||
|
font-size: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-shrink: 0;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
gap: 22rpx;
|
||||||
|
margin-top: 28rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label,
|
||||||
|
.value {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
color: #9a9288;
|
||||||
|
font-size: 22rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
color: #2d2924;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-card {
|
||||||
|
padding: 24rpx;
|
||||||
|
color: #6d655d;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
|
gap: 14rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-row .primary-btn,
|
||||||
|
.action-row .secondary-btn,
|
||||||
|
.action-row .danger-btn {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,196 @@
|
|||||||
|
const planningApi = require('../../api/planning')
|
||||||
|
const productsApi = require('../../api/products')
|
||||||
|
const config = require('../../utils/config')
|
||||||
|
const mock = require('../../utils/mock')
|
||||||
|
const dateUtil = require('../../utils/date')
|
||||||
|
|
||||||
|
const toDurationMinutes = value => {
|
||||||
|
if (typeof value === 'number') return value
|
||||||
|
const parsed = parseInt(String(value || ''), 10)
|
||||||
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : 60
|
||||||
|
}
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
form: {
|
||||||
|
customerName: '',
|
||||||
|
phone: '',
|
||||||
|
appointmentDate: dateUtil.formatDate(new Date()),
|
||||||
|
appointmentTime: '13:00',
|
||||||
|
productId: '',
|
||||||
|
durationMinutes: '',
|
||||||
|
artistId: '',
|
||||||
|
remark: ''
|
||||||
|
},
|
||||||
|
products: [],
|
||||||
|
artists: config.USE_DEV_MOCK_DATA ? mock.artists : [],
|
||||||
|
selectedProduct: {},
|
||||||
|
selectedArtist: {},
|
||||||
|
conflictTip: '',
|
||||||
|
conflictLevel: 'free',
|
||||||
|
loading: false,
|
||||||
|
optionError: ''
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(options = {}) {
|
||||||
|
this.setData({
|
||||||
|
'form.appointmentDate': options.date || dateUtil.formatDate(new Date()),
|
||||||
|
'form.artistId': options.artistId || ''
|
||||||
|
})
|
||||||
|
this.loadOptions()
|
||||||
|
},
|
||||||
|
|
||||||
|
async loadOptions() {
|
||||||
|
let products = []
|
||||||
|
let artists = []
|
||||||
|
let optionError = ''
|
||||||
|
try {
|
||||||
|
const productsData = await productsApi.list({ page: 1, size: 100 })
|
||||||
|
products = productsData.list || productsData || []
|
||||||
|
} catch (error) {
|
||||||
|
optionError = error.message || '项目数据加载失败'
|
||||||
|
products = config.USE_DEV_MOCK_DATA
|
||||||
|
? [
|
||||||
|
{ id: 1, title: '纯色美甲', approximateDuration: '90分钟' },
|
||||||
|
{ id: 2, title: '猫眼延长', approximateDuration: '120分钟' },
|
||||||
|
{ id: 3, title: '手部护理', approximateDuration: '60分钟' }
|
||||||
|
]
|
||||||
|
: []
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const calendar = await planningApi.calendar({
|
||||||
|
startDate: this.data.form.appointmentDate,
|
||||||
|
endDate: this.data.form.appointmentDate
|
||||||
|
})
|
||||||
|
artists = calendar.artists || []
|
||||||
|
} catch (error) {
|
||||||
|
optionError = optionError || error.message || '美甲师数据加载失败'
|
||||||
|
artists = config.USE_DEV_MOCK_DATA ? mock.artists : []
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedArtist = this.data.form.artistId
|
||||||
|
? artists.find(item => String(item.id) === String(this.data.form.artistId)) || {}
|
||||||
|
: {}
|
||||||
|
this.setData({ products, artists, selectedArtist, optionError })
|
||||||
|
this.checkAvailability()
|
||||||
|
},
|
||||||
|
|
||||||
|
onInput(event) {
|
||||||
|
this.setData({
|
||||||
|
[`form.${event.currentTarget.dataset.field}`]: event.detail.value
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
onDateChange(event) {
|
||||||
|
this.setData({ 'form.appointmentDate': event.detail.value })
|
||||||
|
this.loadOptions()
|
||||||
|
},
|
||||||
|
|
||||||
|
onTimeChange(event) {
|
||||||
|
this.setData({ 'form.appointmentTime': event.detail.value })
|
||||||
|
this.checkAvailability()
|
||||||
|
},
|
||||||
|
|
||||||
|
onProductChange(event) {
|
||||||
|
const selectedProduct = this.data.products[Number(event.detail.value)] || {}
|
||||||
|
this.setData({
|
||||||
|
selectedProduct,
|
||||||
|
'form.productId': selectedProduct.id,
|
||||||
|
'form.durationMinutes': String(toDurationMinutes(selectedProduct.approximateDuration))
|
||||||
|
})
|
||||||
|
this.checkAvailability()
|
||||||
|
},
|
||||||
|
|
||||||
|
onArtistChange(event) {
|
||||||
|
const selectedArtist = this.data.artists[Number(event.detail.value)] || {}
|
||||||
|
this.setData({
|
||||||
|
selectedArtist,
|
||||||
|
'form.artistId': selectedArtist.id
|
||||||
|
})
|
||||||
|
this.checkAvailability()
|
||||||
|
},
|
||||||
|
|
||||||
|
async checkAvailability() {
|
||||||
|
const form = this.data.form
|
||||||
|
if (!form.appointmentDate || !form.appointmentTime || !form.artistId) {
|
||||||
|
this.setData({ conflictTip: '', conflictLevel: 'free' })
|
||||||
|
return { ok: true }
|
||||||
|
}
|
||||||
|
const durationMinutes = Number(form.durationMinutes || 0) || 60
|
||||||
|
const startMinute = dateUtil.minutesOfDay(form.appointmentTime)
|
||||||
|
const endMinute = startMinute + durationMinutes
|
||||||
|
if (startMinute < dateUtil.minutesOfDay('10:00') || endMinute > dateUtil.minutesOfDay('22:00')) {
|
||||||
|
const tip = '该时间超出营业时间 10:00-22:00'
|
||||||
|
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||||
|
return { ok: false, tip }
|
||||||
|
}
|
||||||
|
|
||||||
|
let calendar
|
||||||
|
try {
|
||||||
|
calendar = await planningApi.calendar({
|
||||||
|
startDate: form.appointmentDate,
|
||||||
|
endDate: form.appointmentDate,
|
||||||
|
artistId: form.artistId
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
if (config.USE_DEV_MOCK_DATA) {
|
||||||
|
calendar = mock.buildCalendar(form.appointmentDate)
|
||||||
|
} else {
|
||||||
|
const tip = error.message || '暂未获取到排班,无法确认该时段是否可预约'
|
||||||
|
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||||
|
return { ok: false, tip }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const conflicts = (calendar.appointments || []).filter(item => {
|
||||||
|
if (String(item.artistId) !== String(form.artistId) || item.date !== form.appointmentDate) return false
|
||||||
|
if (item.status === 3 || item.statusText === '已取消') return false
|
||||||
|
const itemStart = Number(item.startMinute || dateUtil.minutesOfDay((item.startTime || '').slice(11, 16)))
|
||||||
|
const itemEnd = itemStart + Number(item.durationMinutes || 60)
|
||||||
|
return startMinute < itemEnd && endMinute > itemStart
|
||||||
|
})
|
||||||
|
if (conflicts.length > 0) {
|
||||||
|
const first = conflicts[0]
|
||||||
|
const itemStart = Number(first.startMinute || dateUtil.minutesOfDay((first.startTime || '').slice(11, 16)))
|
||||||
|
const itemEnd = itemStart + Number(first.durationMinutes || 60)
|
||||||
|
const tip = `${this.data.selectedArtist.name || '该美甲师'} ${dateUtil.timeFromMinutes(itemStart)}-${dateUtil.timeFromMinutes(itemEnd)} 已有预约`
|
||||||
|
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||||
|
return { ok: false, tip }
|
||||||
|
}
|
||||||
|
const tip = `${this.data.selectedArtist.name || '该美甲师'} ${form.appointmentTime}-${dateUtil.timeFromMinutes(endMinute)} 可预约`
|
||||||
|
this.setData({ conflictTip: tip, conflictLevel: 'free' })
|
||||||
|
return { ok: true, tip }
|
||||||
|
},
|
||||||
|
|
||||||
|
async submit() {
|
||||||
|
const form = this.data.form
|
||||||
|
if (!form.customerName || !form.phone || !form.productId || !form.artistId) {
|
||||||
|
wx.showToast({ title: '请补全预约信息', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const availability = await this.checkAvailability()
|
||||||
|
if (!availability.ok) {
|
||||||
|
wx.showToast({ title: availability.tip || '该时段不可预约', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.setData({ loading: true })
|
||||||
|
try {
|
||||||
|
const result = await planningApi.createAppointment({
|
||||||
|
...form,
|
||||||
|
productId: Number(form.productId),
|
||||||
|
artistId: Number(form.artistId),
|
||||||
|
durationMinutes: Number(form.durationMinutes || 0) || undefined
|
||||||
|
})
|
||||||
|
wx.redirectTo({ url: `/pages/appointment-detail/index?id=${result.orderItemId}` })
|
||||||
|
} catch (error) {
|
||||||
|
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
this.setData({ loading: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
back() {
|
||||||
|
wx.navigateBack()
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"navigationBarTitleText": "新建预约"
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<view class="page no-tab">
|
||||||
|
<view wx:if="{{optionError}}" class="card error-card">
|
||||||
|
<text class="error-title">选项加载不完整</text>
|
||||||
|
<text class="error-desc">{{optionError}}</text>
|
||||||
|
<button class="compact-btn" bindtap="loadOptions">重试</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="card form-card">
|
||||||
|
<view class="field">
|
||||||
|
<text class="field-label">客户姓名</text>
|
||||||
|
<input value="{{form.customerName}}" data-field="customerName" bindinput="onInput" placeholder="请输入客户姓名" />
|
||||||
|
</view>
|
||||||
|
<view class="field">
|
||||||
|
<text class="field-label">手机号</text>
|
||||||
|
<input value="{{form.phone}}" data-field="phone" bindinput="onInput" placeholder="请输入手机号" />
|
||||||
|
</view>
|
||||||
|
<view class="field">
|
||||||
|
<text class="field-label">预约日期</text>
|
||||||
|
<picker mode="date" value="{{form.appointmentDate}}" bindchange="onDateChange">
|
||||||
|
<view class="field-value">{{form.appointmentDate}}</view>
|
||||||
|
</picker>
|
||||||
|
</view>
|
||||||
|
<view class="field">
|
||||||
|
<text class="field-label">预约时间</text>
|
||||||
|
<picker mode="time" value="{{form.appointmentTime}}" start="10:00" end="22:00" bindchange="onTimeChange">
|
||||||
|
<view class="field-value">{{form.appointmentTime}}</view>
|
||||||
|
</picker>
|
||||||
|
</view>
|
||||||
|
<view class="field">
|
||||||
|
<text class="field-label">项目内容</text>
|
||||||
|
<picker range="{{products}}" range-key="title" bindchange="onProductChange">
|
||||||
|
<view class="field-value">{{selectedProduct.title || '请选择项目'}}</view>
|
||||||
|
</picker>
|
||||||
|
</view>
|
||||||
|
<view class="field">
|
||||||
|
<text class="field-label">预计时长</text>
|
||||||
|
<input value="{{form.durationMinutes}}" data-field="durationMinutes" bindinput="onInput" type="number" placeholder="默认读取项目时长" />
|
||||||
|
<text class="unit">分钟</text>
|
||||||
|
</view>
|
||||||
|
<view class="field">
|
||||||
|
<text class="field-label">指定员工</text>
|
||||||
|
<picker range="{{artists}}" range-key="name" bindchange="onArtistChange">
|
||||||
|
<view class="field-value">{{selectedArtist.name || '请选择美甲师'}}</view>
|
||||||
|
</picker>
|
||||||
|
</view>
|
||||||
|
<view class="field textarea-field">
|
||||||
|
<text class="field-label">备注</text>
|
||||||
|
<textarea value="{{form.remark}}" data-field="remark" bindinput="onInput" placeholder="客户偏好、款式说明" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="capacity-tip card">
|
||||||
|
<text class="tip-title">容量校验</text>
|
||||||
|
<text class="tip-text">保存时会校验营业时间、美甲师休息和同时间段容量,冲突会直接拦截。</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view wx:if="{{conflictTip}}" class="availability-tip card {{conflictLevel}}">
|
||||||
|
<text class="tip-title">时段检查</text>
|
||||||
|
<text class="tip-text">{{conflictTip}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="fixed-bottom">
|
||||||
|
<button class="primary-btn" loading="{{loading}}" bindtap="submit">保存预约</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
.unit {
|
||||||
|
color: #9a9288;
|
||||||
|
font-size: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.textarea-field {
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.capacity-tip {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8rpx;
|
||||||
|
margin-top: 20rpx;
|
||||||
|
padding: 22rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tip-title {
|
||||||
|
color: #4e4942;
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tip-text {
|
||||||
|
color: #90877e;
|
||||||
|
font-size: 24rpx;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.availability-tip {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8rpx;
|
||||||
|
margin-top: 16rpx;
|
||||||
|
padding: 22rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.availability-tip.free {
|
||||||
|
background: #f3faf5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.availability-tip.warn {
|
||||||
|
background: #fff8e8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.availability-tip.danger {
|
||||||
|
background: #fff2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.availability-tip.free .tip-title {
|
||||||
|
color: #4f7d62;
|
||||||
|
}
|
||||||
|
|
||||||
|
.availability-tip.warn .tip-title {
|
||||||
|
color: #a2763d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.availability-tip.danger .tip-title {
|
||||||
|
color: #c36a6a;
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
const planningApi = require('../../api/planning')
|
||||||
|
const config = require('../../utils/config')
|
||||||
|
const mock = require('../../utils/mock')
|
||||||
|
const dateUtil = require('../../utils/date')
|
||||||
|
|
||||||
|
const normalizeArtists = artists => (artists || []).map((item, index) => ({
|
||||||
|
id: item.id || item.userId || item.artistId,
|
||||||
|
name: item.name || item.nickname || item.artistName || `美甲师${index + 1}`,
|
||||||
|
shortName: item.shortName || String(item.name || item.nickname || '师').slice(-1),
|
||||||
|
color: item.color || ['#7BA7C7', '#89A98B', '#A893BC', '#D49A89'][index % 4],
|
||||||
|
statusText: item.statusText || '可接单',
|
||||||
|
availableStatus: item.availableStatus || 'free',
|
||||||
|
availableText: item.availableText || '可接'
|
||||||
|
}))
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
id: '',
|
||||||
|
artists: [],
|
||||||
|
selectedArtistId: '',
|
||||||
|
date: dateUtil.formatDate(new Date()),
|
||||||
|
time: '13:00',
|
||||||
|
loading: false,
|
||||||
|
loadError: false,
|
||||||
|
errorMessage: ''
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(options = {}) {
|
||||||
|
this.setData({ id: options.id || '' })
|
||||||
|
this.loadArtists()
|
||||||
|
},
|
||||||
|
|
||||||
|
async loadArtists() {
|
||||||
|
this.setData({ loadError: false, errorMessage: '' })
|
||||||
|
try {
|
||||||
|
const calendar = await planningApi.calendar({
|
||||||
|
startDate: this.data.date,
|
||||||
|
endDate: this.data.date
|
||||||
|
})
|
||||||
|
this.setData({ artists: normalizeArtists(calendar.artists || []) })
|
||||||
|
} catch (error) {
|
||||||
|
if (config.USE_DEV_MOCK_DATA) {
|
||||||
|
this.setData({ artists: normalizeArtists(mock.artists) })
|
||||||
|
} else {
|
||||||
|
this.setData({
|
||||||
|
artists: [],
|
||||||
|
loadError: true,
|
||||||
|
errorMessage: error.message || '美甲师可接状态加载失败,请检查服务连接后重试'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
selectArtist(event) {
|
||||||
|
this.setData({ selectedArtistId: event.currentTarget.dataset.id })
|
||||||
|
},
|
||||||
|
|
||||||
|
onDateChange(event) {
|
||||||
|
this.setData({ date: event.detail.value, selectedArtistId: '' })
|
||||||
|
this.loadArtists()
|
||||||
|
},
|
||||||
|
|
||||||
|
onTimeChange(event) {
|
||||||
|
this.setData({ time: event.detail.value })
|
||||||
|
},
|
||||||
|
|
||||||
|
async submit() {
|
||||||
|
if (this.data.loadError) {
|
||||||
|
wx.showToast({ title: '请先重新加载可接员工', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!this.data.selectedArtistId) {
|
||||||
|
wx.showToast({ title: '请选择美甲师', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.setData({ loading: true })
|
||||||
|
try {
|
||||||
|
await planningApi.moveAppointment(this.data.id, {
|
||||||
|
artistId: Number(this.data.selectedArtistId),
|
||||||
|
appointmentDate: this.data.date,
|
||||||
|
appointmentTime: this.data.time
|
||||||
|
})
|
||||||
|
wx.showToast({ title: '已改派' })
|
||||||
|
setTimeout(() => wx.navigateBack(), 500)
|
||||||
|
} catch (error) {
|
||||||
|
wx.showToast({ title: error.message || '改派失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
this.setData({ loading: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
back() {
|
||||||
|
wx.navigateBack()
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"navigationBarTitleText": "改派员工"
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<view class="page no-tab">
|
||||||
|
<view wx:if="{{loadError}}" class="card error-card">
|
||||||
|
<text class="error-title">数据加载失败</text>
|
||||||
|
<text class="error-desc">{{errorMessage}}</text>
|
||||||
|
<button class="compact-btn" bindtap="loadArtists">重试</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view wx:elif="{{!artists.length}}" class="empty">暂无可改派美甲师</view>
|
||||||
|
|
||||||
|
<view wx:else class="list">
|
||||||
|
<view wx:for="{{artists}}" wx:key="id" class="card transfer-card {{selectedArtistId == item.id ? 'active' : ''}}" data-id="{{item.id}}" bindtap="selectArtist">
|
||||||
|
<view class="row between">
|
||||||
|
<view class="row">
|
||||||
|
<view class="chip-dot large" style="background: {{item.color}};"></view>
|
||||||
|
<view>
|
||||||
|
<text class="artist-name">{{item.name}}</text>
|
||||||
|
<text class="artist-status">{{item.statusText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<text class="tag {{item.availableStatus}}">{{item.availableText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="card form-card section">
|
||||||
|
<view class="field">
|
||||||
|
<text class="field-label">新日期</text>
|
||||||
|
<picker mode="date" value="{{date}}" bindchange="onDateChange">
|
||||||
|
<view class="field-value">{{date}}</view>
|
||||||
|
</picker>
|
||||||
|
</view>
|
||||||
|
<view class="field">
|
||||||
|
<text class="field-label">新时间</text>
|
||||||
|
<picker mode="time" value="{{time}}" start="10:00" end="22:00" bindchange="onTimeChange">
|
||||||
|
<view class="field-value">{{time}}</view>
|
||||||
|
</picker>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="fixed-bottom">
|
||||||
|
<button class="primary-btn" loading="{{loading}}" bindtap="submit">确认改派</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
.transfer-card {
|
||||||
|
padding: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.transfer-card.active {
|
||||||
|
outline: 3rpx solid #8fb89a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chip-dot.large {
|
||||||
|
width: 24rpx;
|
||||||
|
height: 24rpx;
|
||||||
|
margin-right: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.artist-name,
|
||||||
|
.artist-status {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.artist-name {
|
||||||
|
color: #25211d;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.artist-status {
|
||||||
|
margin-top: 6rpx;
|
||||||
|
color: #948c83;
|
||||||
|
font-size: 22rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag.free {
|
||||||
|
background: #e5eee9;
|
||||||
|
color: #55786d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag.busy {
|
||||||
|
background: #fbedd7;
|
||||||
|
color: #a5722a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag.full {
|
||||||
|
background: #f8e2e6;
|
||||||
|
color: #b06070;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
id: '',
|
||||||
|
avatarText: '客',
|
||||||
|
customer: { name: '王女士', phone: '138****1201' },
|
||||||
|
stats: { orderCount: 12, amount: 2860, lastTime: '06-01' },
|
||||||
|
orders: [
|
||||||
|
{ id: 1, date: '2026-06-01', project: '纯色美甲', amount: 168, artist: '小王' },
|
||||||
|
{ id: 2, date: '2026-05-18', project: '猫眼延长', amount: 268, artist: '小李' },
|
||||||
|
{ id: 3, date: '2026-05-02', project: '手部护理', amount: 98, artist: '小张' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(options) {
|
||||||
|
this.setData({ id: options.id || '' })
|
||||||
|
},
|
||||||
|
|
||||||
|
createAppointment() {
|
||||||
|
wx.navigateTo({ url: '/pages/appointment-form/index' })
|
||||||
|
},
|
||||||
|
|
||||||
|
back() {
|
||||||
|
wx.navigateBack()
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<view class="page no-tab">
|
||||||
|
<view class="card customer-head">
|
||||||
|
<view class="customer-identity">
|
||||||
|
<view class="avatar">{{avatarText}}</view>
|
||||||
|
<view>
|
||||||
|
<text class="customer-name">{{customer.name}}</text>
|
||||||
|
<text class="customer-phone">{{customer.phone}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<button class="small-action" bindtap="createAppointment">新预约</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="stats">
|
||||||
|
<view class="card stat">
|
||||||
|
<text class="stat-value">{{stats.orderCount}}</text>
|
||||||
|
<text class="stat-label">累计订单</text>
|
||||||
|
</view>
|
||||||
|
<view class="card stat">
|
||||||
|
<text class="stat-value">¥{{stats.amount}}</text>
|
||||||
|
<text class="stat-label">累计消费</text>
|
||||||
|
</view>
|
||||||
|
<view class="card stat">
|
||||||
|
<text class="stat-value">{{stats.lastTime}}</text>
|
||||||
|
<text class="stat-label">最近消费</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="section">
|
||||||
|
<view class="section-title">历史订单</view>
|
||||||
|
<view class="list">
|
||||||
|
<view wx:for="{{orders}}" wx:key="id" class="card list-card order-card">
|
||||||
|
<view>
|
||||||
|
<text class="order-title">{{item.project}}</text>
|
||||||
|
<text class="meta">{{item.date}} · {{item.artist}}</text>
|
||||||
|
</view>
|
||||||
|
<text class="amount">¥{{item.amount}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
.customer-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 18rpx;
|
||||||
|
padding: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-identity {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
gap: 18rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 84rpx;
|
||||||
|
height: 84rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #e5eee9;
|
||||||
|
color: #5b7f73;
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-name,
|
||||||
|
.customer-phone {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-name {
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-phone {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
color: #928a81;
|
||||||
|
font-size: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
gap: 14rpx;
|
||||||
|
margin-top: 18rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat {
|
||||||
|
padding: 16rpx 12rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-value,
|
||||||
|
.stat-label {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-value {
|
||||||
|
color: #26231f;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-label {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
color: #91897f;
|
||||||
|
font-size: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-card {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-title {
|
||||||
|
display: block;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount {
|
||||||
|
color: #6f8f83;
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
const customersApi = require('../../api/customers')
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
keyword: '',
|
||||||
|
customers: []
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
this.loadCustomers()
|
||||||
|
},
|
||||||
|
|
||||||
|
onSearchInput(event) {
|
||||||
|
this.setData({ keyword: event.detail.value })
|
||||||
|
clearTimeout(this._timer)
|
||||||
|
this._timer = setTimeout(() => this.loadCustomers(), 300)
|
||||||
|
},
|
||||||
|
|
||||||
|
async loadCustomers() {
|
||||||
|
const fallback = [
|
||||||
|
{ id: 1, name: '王女士', phone: '138****1201', lastTime: '2026-06-01' },
|
||||||
|
{ id: 2, name: '陈女士', phone: '136****8842', lastTime: '2026-05-29' },
|
||||||
|
{ id: 3, name: '林女士', phone: '159****6671', lastTime: '2026-05-27' }
|
||||||
|
]
|
||||||
|
try {
|
||||||
|
const data = await customersApi.list({ keyword: this.data.keyword, page: 1, size: 30 })
|
||||||
|
const list = data.list || data || []
|
||||||
|
this.setData({
|
||||||
|
customers: list.map(item => ({
|
||||||
|
id: item.id,
|
||||||
|
name: item.nickname || item.name || item.account || '客户',
|
||||||
|
phone: item.contactPhone || item.phone || '未填写',
|
||||||
|
lastTime: item.lastOrderTime || item.lastConsumeTime || '-'
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
this.setData({ customers: fallback })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
openDetail(event) {
|
||||||
|
wx.navigateTo({ url: `/pages/customer-detail/index?id=${event.currentTarget.dataset.id}` })
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<view class="page">
|
||||||
|
<view class="search-card card">
|
||||||
|
<input value="{{keyword}}" bindinput="onSearchInput" placeholder="搜索客户姓名或手机号" />
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="list section">
|
||||||
|
<view wx:for="{{customers}}" wx:key="id" class="card list-card customer-card" data-id="{{item.id}}" bindtap="openDetail">
|
||||||
|
<view>
|
||||||
|
<text class="name">{{item.name}}</text>
|
||||||
|
<text class="meta">{{item.phone}}</text>
|
||||||
|
<text class="meta">最近消费 {{item.lastTime}}</text>
|
||||||
|
</view>
|
||||||
|
<text class="arrow">›</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
.search-card {
|
||||||
|
padding: 0 24rpx;
|
||||||
|
height: 84rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-card input {
|
||||||
|
width: 100%;
|
||||||
|
font-size: 26rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-card {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name,
|
||||||
|
.meta {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name {
|
||||||
|
color: #292520;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
color: #928a81;
|
||||||
|
font-size: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow {
|
||||||
|
color: #b0a79e;
|
||||||
|
font-size: 48rpx;
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
const employeesApi = require('../../api/employees')
|
||||||
|
const config = require('../../utils/config')
|
||||||
|
const mock = require('../../utils/mock')
|
||||||
|
|
||||||
|
const normalizeEmployee = (item = {}) => ({
|
||||||
|
id: item.userId || item.id,
|
||||||
|
name: item.nickname || item.name || item.artistName || '美甲师',
|
||||||
|
shortName: (item.nickname || item.name || item.artistName || '师').slice(-1),
|
||||||
|
color: item.color || '#7BA7C7',
|
||||||
|
monthOrders: item.monthOrders || item.orderCount || 0,
|
||||||
|
monthAmount: item.monthAmount || item.turnover || 0,
|
||||||
|
avgAmount: item.avgAmount || item.averageAmount || 0
|
||||||
|
})
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
id: '',
|
||||||
|
employee: {},
|
||||||
|
loadError: false,
|
||||||
|
errorMessage: ''
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(options = {}) {
|
||||||
|
const id = options.id || ''
|
||||||
|
this.setData({ id })
|
||||||
|
this.loadEmployee()
|
||||||
|
},
|
||||||
|
|
||||||
|
async loadEmployee() {
|
||||||
|
this.setData({ loadError: false, errorMessage: '' })
|
||||||
|
try {
|
||||||
|
const employee = await employeesApi.detail(this.data.id)
|
||||||
|
this.setData({ employee: normalizeEmployee(employee) })
|
||||||
|
} catch (error) {
|
||||||
|
if (config.USE_DEV_MOCK_DATA) {
|
||||||
|
const artist = mock.artists.find(item => String(item.id) === String(this.data.id)) || mock.artists[0]
|
||||||
|
this.setData({
|
||||||
|
employee: normalizeEmployee({
|
||||||
|
...artist,
|
||||||
|
monthOrders: 32,
|
||||||
|
monthAmount: 5800,
|
||||||
|
avgAmount: 181
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.setData({
|
||||||
|
employee: {},
|
||||||
|
loadError: true,
|
||||||
|
errorMessage: error.message || '员工详情加载失败,请检查服务连接后重试'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
go(event) {
|
||||||
|
if (this.data.loadError) {
|
||||||
|
wx.showToast({ title: '请先重新加载员工详情', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
wx.navigateTo({ url: `${event.currentTarget.dataset.url}?id=${this.data.id}` })
|
||||||
|
},
|
||||||
|
|
||||||
|
back() {
|
||||||
|
wx.navigateBack()
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<view class="page no-tab">
|
||||||
|
<view wx:if="{{loadError}}" class="card error-card">
|
||||||
|
<text class="error-title">数据加载失败</text>
|
||||||
|
<text class="error-desc">{{errorMessage}}</text>
|
||||||
|
<button class="compact-btn" bindtap="loadEmployee">重试</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<block wx:else>
|
||||||
|
<view class="card employee-head">
|
||||||
|
<view class="avatar" style="background: {{employee.color}};">{{employee.shortName}}</view>
|
||||||
|
<view>
|
||||||
|
<text class="employee-name">{{employee.name}}</text>
|
||||||
|
<text class="tag" style="background: {{employee.color}}; color: #fff;">员工色</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="stats">
|
||||||
|
<view class="card stat">
|
||||||
|
<text class="stat-value">{{employee.monthOrders}}</text>
|
||||||
|
<text class="stat-label">本月订单</text>
|
||||||
|
</view>
|
||||||
|
<view class="card stat">
|
||||||
|
<text class="stat-value">¥{{employee.monthAmount}}</text>
|
||||||
|
<text class="stat-label">本月营业额</text>
|
||||||
|
</view>
|
||||||
|
<view class="card stat">
|
||||||
|
<text class="stat-value">¥{{employee.avgAmount}}</text>
|
||||||
|
<text class="stat-label">平均客单价</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="section">
|
||||||
|
<view class="menu-grid">
|
||||||
|
<view class="card menu-card" data-url="/pages/schedule-setting/index" bindtap="go">排班设置</view>
|
||||||
|
<view class="card menu-card" data-url="/pages/leave-management/index" bindtap="go">请假管理</view>
|
||||||
|
<view class="card menu-card" data-url="/pages/color-setting/index" bindtap="go">颜色设置</view>
|
||||||
|
<view class="card menu-card" data-url="/pages/employee-orders/index" bindtap="go">订单记录</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
.employee-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 20rpx;
|
||||||
|
padding: 28rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 94rpx;
|
||||||
|
height: 94rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 34rpx;
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.employee-name {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 12rpx;
|
||||||
|
font-size: 34rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
gap: 14rpx;
|
||||||
|
margin-top: 18rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat {
|
||||||
|
padding: 18rpx 12rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-value,
|
||||||
|
.stat-label {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-value {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-label {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
color: #91897f;
|
||||||
|
font-size: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
gap: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-card {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-height: 148rpx;
|
||||||
|
padding: 24rpx;
|
||||||
|
color: #302c27;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
const employeesApi = require('../../api/employees')
|
||||||
|
|
||||||
|
const EMPLOYEE_COLORS = ['#7BA7C7', '#89A98B', '#A893BC', '#D49A89', '#C9A66B', '#7E9A9A']
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
employees: [],
|
||||||
|
loadError: false,
|
||||||
|
errorMessage: ''
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
this.loadEmployees()
|
||||||
|
},
|
||||||
|
|
||||||
|
async loadEmployees() {
|
||||||
|
this.setData({ loadError: false, errorMessage: '' })
|
||||||
|
try {
|
||||||
|
const data = await employeesApi.list({ page: 1, size: 50 })
|
||||||
|
const list = data.list || data || []
|
||||||
|
this.setData({
|
||||||
|
employees: list.map((item, index) => ({
|
||||||
|
id: item.userId || item.id,
|
||||||
|
name: item.nickname || item.name || item.artistName || `美甲师${index + 1}`,
|
||||||
|
shortName: (item.nickname || item.name || '师').slice(-1),
|
||||||
|
color: item.color || EMPLOYEE_COLORS[index % EMPLOYEE_COLORS.length],
|
||||||
|
monthOrders: item.monthOrders || item.orderCount || 0,
|
||||||
|
monthAmount: item.monthAmount || item.turnover || 0
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
this.setData({
|
||||||
|
employees: [],
|
||||||
|
loadError: true,
|
||||||
|
errorMessage: error.message || '员工数据加载失败,请检查服务连接后重试'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
openDetail(event) {
|
||||||
|
wx.navigateTo({ url: `/pages/employee-detail/index?id=${event.currentTarget.dataset.id}` })
|
||||||
|
},
|
||||||
|
|
||||||
|
addEmployee() {
|
||||||
|
wx.showToast({ title: '员工创建沿用后台账号', icon: 'none' })
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<view class="page">
|
||||||
|
<view class="list-heading">
|
||||||
|
<text>美甲师</text>
|
||||||
|
<button class="compact-btn" bindtap="addEmployee">新增</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view wx:if="{{loadError}}" class="card error-card">
|
||||||
|
<text class="error-title">数据加载失败</text>
|
||||||
|
<text class="error-desc">{{errorMessage}}</text>
|
||||||
|
<button class="compact-btn" bindtap="loadEmployees">重试</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view wx:elif="{{!employees.length}}" class="empty">暂无员工数据</view>
|
||||||
|
|
||||||
|
<view wx:else class="list">
|
||||||
|
<view wx:for="{{employees}}" wx:key="id" class="card employee-card" data-id="{{item.id}}" bindtap="openDetail">
|
||||||
|
<view class="employee-left">
|
||||||
|
<view class="avatar" style="background: {{item.color}};">{{item.shortName}}</view>
|
||||||
|
<view>
|
||||||
|
<text class="employee-name">{{item.name}}</text>
|
||||||
|
<text class="employee-meta">本月 {{item.monthOrders}} 单 · ¥{{item.monthAmount}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="color-pill" style="background: {{item.color}};"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
.list-heading {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-start;
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: 16rpx;
|
||||||
|
color: #4c4740;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-heading text {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-heading .compact-btn {
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.employee-card {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 22rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.employee-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 18rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 78rpx;
|
||||||
|
height: 78rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.employee-name,
|
||||||
|
.employee-meta {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.employee-name {
|
||||||
|
color: #25211d;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.employee-meta {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
color: #91897f;
|
||||||
|
font-size: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-pill {
|
||||||
|
width: 44rpx;
|
||||||
|
height: 18rpx;
|
||||||
|
border-radius: 999rpx;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
const dateUtil = require('../../utils/date')
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
types: ['订单数据', '客户数据', '员工数据'],
|
||||||
|
type: '订单数据',
|
||||||
|
startDate: dateUtil.formatDate(dateUtil.startOfMonth(new Date())),
|
||||||
|
endDate: dateUtil.formatDate(new Date())
|
||||||
|
},
|
||||||
|
onTypeChange(event) { this.setData({ type: this.data.types[Number(event.detail.value)] }) },
|
||||||
|
onStartDate(event) { this.setData({ startDate: event.detail.value }) },
|
||||||
|
onEndDate(event) { this.setData({ endDate: event.detail.value }) },
|
||||||
|
exportExcel() { wx.showToast({ title: '导出任务已创建', icon: 'none' }) },
|
||||||
|
back() { wx.navigateBack() }
|
||||||
|
})
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<view class="page no-tab">
|
||||||
|
<view class="card form-card">
|
||||||
|
<view class="field"><text class="field-label">导出类型</text><picker range="{{types}}" bindchange="onTypeChange"><view class="field-value">{{type}}</view></picker></view>
|
||||||
|
<view class="field"><text class="field-label">开始日期</text><picker mode="date" value="{{startDate}}" bindchange="onStartDate"><view class="field-value">{{startDate}}</view></picker></view>
|
||||||
|
<view class="field"><text class="field-label">结束日期</text><picker mode="date" value="{{endDate}}" bindchange="onEndDate"><view class="field-value">{{endDate}}</view></picker></view>
|
||||||
|
</view>
|
||||||
|
<view class="fixed-bottom"><button class="primary-btn" bindtap="exportExcel">导出 Excel</button></view>
|
||||||
|
</view>
|
||||||