one
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
7
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"Vue.volar",
|
||||||
|
"tauri-apps.tauri-vscode",
|
||||||
|
"rust-lang.rust-analyzer"
|
||||||
|
]
|
||||||
|
}
|
||||||
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Tauri + Vue 3
|
||||||
|
|
||||||
|
This template should help get you started developing with Tauri + Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||||
|
|
||||||
|
## Recommended IDE Setup
|
||||||
|
|
||||||
|
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
|
||||||
14
index.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Tauri + Vue 3 App</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module" src="/src/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
24
package.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "tms_tools",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.1.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"tauri": "tauri"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tauri-apps/api": "^2",
|
||||||
|
"@tauri-apps/plugin-opener": "^2",
|
||||||
|
"element-plus": "^2.10.4",
|
||||||
|
"vue": "^3.5.13",
|
||||||
|
"vue-router": "^4.5.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tauri-apps/cli": "^2",
|
||||||
|
"@vitejs/plugin-vue": "^5.2.1",
|
||||||
|
"vite": "^6.0.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
1105
pnpm-lock.yaml
generated
Normal file
6
public/tauri.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
|
||||||
|
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.5 KiB |
1
public/vite.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.5 KiB |
7
src-tauri/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
|
||||||
|
# Generated by Tauri
|
||||||
|
# will have schema files for capabilities auto-completion
|
||||||
|
/gen/schemas
|
||||||
5917
src-tauri/Cargo.lock
generated
Normal file
32
src-tauri/Cargo.toml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
[package]
|
||||||
|
name = "tms_tools"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "A Tauri App"
|
||||||
|
authors = ["you"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
# The `_lib` suffix may seem redundant but it is necessary
|
||||||
|
# to make the lib name unique and wouldn't conflict with the bin name.
|
||||||
|
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
||||||
|
name = "tms_tools_lib"
|
||||||
|
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
tauri-build = { version = "2", features = [] }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tauri = { version = "2", features = [] }
|
||||||
|
tauri-plugin-opener = "2"
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
|
tokio-postgres = { version = "0.7.10", features = ["with-chrono-0_4"] }
|
||||||
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
|
reqwest = { version = "0.12.22", features = ["json", "cookies"] }
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
scraper = "0.19.0"
|
||||||
|
tms_service = { path = "./tms_service" }
|
||||||
|
|
||||||
3
src-tauri/build.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
tauri_build::build()
|
||||||
|
}
|
||||||
10
src-tauri/capabilities/default.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"$schema": "../gen/schemas/desktop-schema.json",
|
||||||
|
"identifier": "default",
|
||||||
|
"description": "Capability for the main window",
|
||||||
|
"windows": ["main"],
|
||||||
|
"permissions": [
|
||||||
|
"core:default",
|
||||||
|
"opener:default"
|
||||||
|
]
|
||||||
|
}
|
||||||
BIN
src-tauri/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 974 B |
BIN
src-tauri/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src-tauri/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
src-tauri/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
src-tauri/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
src-tauri/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 903 B |
BIN
src-tauri/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
src-tauri/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src-tauri/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src-tauri/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src-tauri/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src-tauri/icons/icon.icns
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
src-tauri/icons/icon.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
1
src-tauri/openai/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
1671
src-tauri/openai/Cargo.lock
generated
Normal file
10
src-tauri/openai/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "openai"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
reqwest = "0.12.22"
|
||||||
|
tokio = { version = "1.38.0", features = ["full"] }
|
||||||
|
serde = { version = "1.0.203", features = ["derive"] }
|
||||||
|
serde_json = "1.0.120"
|
||||||
93
src-tauri/openai/src/lib.rs
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
const API_KEY: &str = "AIzaSyDBienhzI5Y3o9N4foi7QQRarTtuOIsVJg"; // 请替换为您的OpenAI API密钥
|
||||||
|
const API_URL: &str = "https://melodic-bonbon-359e24.netlify.app/edge/v1/chat/completions";
|
||||||
|
|
||||||
|
// --- Structs for Serialization (Request) ---
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct ChatCompletionRequest<'a> {
|
||||||
|
model: &'a str,
|
||||||
|
messages: Vec<RequestMessage<'a>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct RequestMessage<'a> {
|
||||||
|
role: &'a str,
|
||||||
|
content: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Structs for Deserialization (Response) ---
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct ChatCompletionResponse {
|
||||||
|
choices: Vec<Choice>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Choice {
|
||||||
|
message: ResponseMessage,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct ResponseMessage {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
role: String,
|
||||||
|
content: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn ask_openai(user_prompt: &str, system_prompt: &str) -> Result<String, reqwest::Error> {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
|
let messages = vec![
|
||||||
|
RequestMessage {
|
||||||
|
role: "system",
|
||||||
|
content: system_prompt,
|
||||||
|
},
|
||||||
|
RequestMessage {
|
||||||
|
role: "user",
|
||||||
|
content: user_prompt,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
let request_body = ChatCompletionRequest {
|
||||||
|
model: "gemini-2.5-flash",
|
||||||
|
messages,
|
||||||
|
};
|
||||||
|
|
||||||
|
let response = client
|
||||||
|
.post(API_URL)
|
||||||
|
.bearer_auth(API_KEY)
|
||||||
|
.json(&request_body)
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let response = response.error_for_status()?;
|
||||||
|
let chat_response = response.json::<ChatCompletionResponse>().await?;
|
||||||
|
|
||||||
|
if let Some(choice) = chat_response.choices.get(0) {
|
||||||
|
Ok(choice.message.content.clone())
|
||||||
|
} else {
|
||||||
|
Ok("No response from AI.".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_ask_openai() {
|
||||||
|
// 请注意:此测试会真实调用OpenAI API并产生费用。
|
||||||
|
// 请确保您已经设置了正确的API_KEY。
|
||||||
|
// 在实际测试中,您可能希望使用模拟(mocking)来避免网络调用。
|
||||||
|
let user_prompt = "Hello, who are you?";
|
||||||
|
let system_prompt = "You are a helpful assistant.";
|
||||||
|
let result = ask_openai(user_prompt, system_prompt).await;
|
||||||
|
if let Err(e) = &result {
|
||||||
|
eprintln!("API call failed with error: {}", e);
|
||||||
|
}
|
||||||
|
assert!(result.is_ok());
|
||||||
|
println!("AI Response: {}", result.unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
585
src-tauri/src/lib.rs
Normal file
@@ -0,0 +1,585 @@
|
|||||||
|
use std::sync::Mutex;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use tokio_postgres::{NoTls, Error};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use scraper::{Html, Selector};
|
||||||
|
use tms_service;
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::time::sleep;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref COOKIE_STORAGE: Mutex<Option<String>> = Mutex::new(None);
|
||||||
|
static ref USERNAME_STORAGE: Mutex<Option<String>> = Mutex::new(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
struct LoginResult {
|
||||||
|
success: bool,
|
||||||
|
message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
struct ApiLoginResponse {
|
||||||
|
msg: String,
|
||||||
|
// a_id: i32,
|
||||||
|
// username: String,
|
||||||
|
// code: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize, Debug)]
|
||||||
|
struct WorkOrder {
|
||||||
|
gdid: String,
|
||||||
|
n2n: String,
|
||||||
|
messageq: String,
|
||||||
|
messagea: Option<String>,
|
||||||
|
iscreate: i32,
|
||||||
|
isfeedback: i32,
|
||||||
|
isclose: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize, Debug)]
|
||||||
|
struct WorkOrderResponse {
|
||||||
|
orders: Vec<WorkOrder>,
|
||||||
|
total: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn login(username: String, password: String) -> Result<LoginResult, String> {
|
||||||
|
// First, authenticate against the external API
|
||||||
|
let client = reqwest::Client::builder().cookie_store(true).build().unwrap();
|
||||||
|
let mut params = HashMap::new();
|
||||||
|
params.insert("username", username.clone());
|
||||||
|
params.insert("password", password);
|
||||||
|
|
||||||
|
let res = client.post("https://c.baobaot.com/user/ajax_login")
|
||||||
|
.form(¶ms)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("API请求失败: {}", e))?;
|
||||||
|
|
||||||
|
if res.status().is_success() {
|
||||||
|
if let Some(cookie) = res.headers().get("set-cookie") {
|
||||||
|
if let Ok(cookie_str) = cookie.to_str() {
|
||||||
|
let mut storage = COOKIE_STORAGE.lock().unwrap();
|
||||||
|
*storage = Some(cookie_str.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let api_response = res.json::<ApiLoginResponse>().await.map_err(|e| format!("解析API响应失败: {}", e))?;
|
||||||
|
if api_response.msg != "登录成功" {
|
||||||
|
return Ok(LoginResult {
|
||||||
|
success: false,
|
||||||
|
message: api_response.msg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let mut user_storage = USERNAME_STORAGE.lock().unwrap();
|
||||||
|
*user_storage = Some(username.clone());
|
||||||
|
} else {
|
||||||
|
let error_text = res.text().await.unwrap_or_else(|_| "无法读取API错误响应".to_string());
|
||||||
|
return Err(format!("API请求返回错误状态: {}", error_text));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If API login is successful, proceed with database operations
|
||||||
|
let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools";
|
||||||
|
let (mut client, connection) = match tokio_postgres::connect(db_url, NoTls).await {
|
||||||
|
Ok(res) => res,
|
||||||
|
Err(e) => return Err(format!("数据库连接失败: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = connection.await {
|
||||||
|
eprintln!("connection error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let query = format!("SELECT EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = '{}');", username);
|
||||||
|
let row = match client.query_one(&query, &[]).await {
|
||||||
|
Ok(row) => row,
|
||||||
|
Err(e) => return Err(format!("查询表是否存在时出错: {}", e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let exists: bool = row.get(0);
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
Ok(LoginResult {
|
||||||
|
success: true,
|
||||||
|
message: format!("用户 {} 登录成功", username),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
let create_table_query = format!(
|
||||||
|
"CREATE TABLE \"{}\" (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
code VARCHAR(255),
|
||||||
|
time TIMESTAMP,
|
||||||
|
n2n VARCHAR(255),
|
||||||
|
q TEXT,
|
||||||
|
a TEXT,
|
||||||
|
isfeedback INTEGER DEFAULT 0,
|
||||||
|
isclose INTEGER DEFAULT 0
|
||||||
|
)",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
match client.batch_execute(&create_table_query).await {
|
||||||
|
Ok(_) => Ok(LoginResult {
|
||||||
|
success: true,
|
||||||
|
message: format!("用户 {} 的表已创建", username),
|
||||||
|
}),
|
||||||
|
Err(e) => Err(format!("创建表时出错: {}", e)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn get_cookie() -> Option<String> {
|
||||||
|
COOKIE_STORAGE.lock().unwrap().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn get_dashboard_username() -> Result<String, String> {
|
||||||
|
let cookie = COOKIE_STORAGE.lock().unwrap().clone();
|
||||||
|
if cookie.is_none() {
|
||||||
|
return Err("未找到登录Cookie".to_string());
|
||||||
|
}
|
||||||
|
let cookie = cookie.unwrap();
|
||||||
|
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let res = client.get("http://c.baobaot.com/admin/dashboard")
|
||||||
|
.header("Cookie", cookie)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("请求失败: {}", e))?;
|
||||||
|
|
||||||
|
if res.status().is_success() {
|
||||||
|
let body = res.text().await.map_err(|e| format!("读取响应失败: {}", e))?;
|
||||||
|
let document = Html::parse_document(&body);
|
||||||
|
let selector = Selector::parse("span.username").map_err(|_| "无效的选择器".to_string())?;
|
||||||
|
|
||||||
|
if let Some(element) = document.select(&selector).next() {
|
||||||
|
let username = element.inner_html();
|
||||||
|
Ok(username)
|
||||||
|
} else {
|
||||||
|
Err("未找到指定的元素".to_string())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(format!("请求失败,状态码: {}", res.status()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn get_workorders(range: String) -> Result<WorkOrderResponse, String> {
|
||||||
|
let username = USERNAME_STORAGE.lock().unwrap().clone().ok_or("用户未登录".to_string())?;
|
||||||
|
let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools";
|
||||||
|
let (mut client, connection) = tokio_postgres::connect(db_url, NoTls)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("数据库连接失败: {}", e))?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = connection.await {
|
||||||
|
eprintln!("connection error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let query_string = if range == "month" {
|
||||||
|
format!(
|
||||||
|
"SELECT code, n2n, q, a, isfeedback, isclose FROM \"{}\" WHERE date_trunc('month', time) = date_trunc('month', current_date) ORDER BY time DESC",
|
||||||
|
username
|
||||||
|
)
|
||||||
|
} else { // Default to "today"
|
||||||
|
format!(
|
||||||
|
"SELECT code, n2n, q, a, isfeedback, isclose FROM \"{}\" WHERE time >= current_date ORDER BY time DESC",
|
||||||
|
username
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let rows = client
|
||||||
|
.query(&query_string, &[])
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("查询工单失败: {}", e))?;
|
||||||
|
|
||||||
|
let orders: Vec<WorkOrder> = rows
|
||||||
|
.into_iter()
|
||||||
|
.map(|row| {
|
||||||
|
WorkOrder {
|
||||||
|
gdid: row.get(0),
|
||||||
|
n2n: row.get(1),
|
||||||
|
messageq: row.get(2),
|
||||||
|
messagea: row.get(3),
|
||||||
|
iscreate: 0, // All from DB are considered created
|
||||||
|
isfeedback: row.get(4),
|
||||||
|
isclose: row.get(5),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let total = orders.len() as i32;
|
||||||
|
|
||||||
|
Ok(WorkOrderResponse {
|
||||||
|
orders,
|
||||||
|
total,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn create_ticket_command(n2p: String, massage_q: String, wx: String) -> Result<String, String> {
|
||||||
|
let cookie = COOKIE_STORAGE.lock().unwrap().clone().ok_or("未找到登录Cookie")?;
|
||||||
|
tms_service::create_ticket(&cookie, &n2p, &massage_q, &wx)
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn insert_workorder(code: String, n2n: String, q: String, a: String) -> Result<(), String> {
|
||||||
|
let username = USERNAME_STORAGE.lock().unwrap().clone().ok_or("用户未登录".to_string())?;
|
||||||
|
let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools";
|
||||||
|
let (mut client, connection) = tokio_postgres::connect(db_url, NoTls)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("数据库连接失败: {}", e))?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = connection.await {
|
||||||
|
eprintln!("connection error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let query = format!(
|
||||||
|
"INSERT INTO \"{}\" (code, time, n2n, q, a, isfeedback, isclose) VALUES ($1, NOW(), $2, $3, $4, 0, 0)",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
|
||||||
|
client
|
||||||
|
.execute(&query, &[&code, &n2n, &q, &a])
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("插入工单失败: {}", e))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn feedback_workorder(gdid: String, messagea: String) -> Result<(), String> {
|
||||||
|
// Step 1: Call the remote feedback service
|
||||||
|
let cookie = COOKIE_STORAGE.lock().unwrap().clone().ok_or("未找到登录Cookie")?;
|
||||||
|
tms_service::feedback(&cookie, &messagea, &gdid)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("远程反馈失败: {}", e))?;
|
||||||
|
|
||||||
|
// Step 2: If remote feedback is successful, update the local database
|
||||||
|
let username = USERNAME_STORAGE.lock().unwrap().clone().ok_or("用户未登录".to_string())?;
|
||||||
|
let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools";
|
||||||
|
let (mut client, connection) = tokio_postgres::connect(db_url, NoTls)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("数据库连接失败: {}", e))?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = connection.await {
|
||||||
|
eprintln!("connection error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let query = format!(
|
||||||
|
"UPDATE \"{}\" SET a = $1, isfeedback = 1 WHERE code = $2",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
|
||||||
|
client
|
||||||
|
.execute(&query, &[&messagea, &gdid])
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("更新数据库失败: {}", e))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn feedback_today_workorders(messagea: String) -> Result<String, String> {
|
||||||
|
let username = USERNAME_STORAGE.lock().unwrap().clone().ok_or("用户未登录".to_string())?;
|
||||||
|
let cookie = COOKIE_STORAGE.lock().unwrap().clone().ok_or("未找到登录Cookie")?;
|
||||||
|
let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools";
|
||||||
|
let (mut client, connection) = tokio_postgres::connect(db_url, NoTls)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("数据库连接失败: {}", e))?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = connection.await {
|
||||||
|
eprintln!("connection error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let query_today_unfeedbacked = format!(
|
||||||
|
"SELECT code FROM \"{}\" WHERE time >= current_date AND isfeedback = 0",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
|
||||||
|
let rows = client
|
||||||
|
.query(&query_today_unfeedbacked, &[])
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("查询今日未反馈工单失败: {}", e))?;
|
||||||
|
|
||||||
|
let mut success_count = 0;
|
||||||
|
let total_count = rows.len();
|
||||||
|
|
||||||
|
for row in rows {
|
||||||
|
sleep(Duration::from_millis(200)).await;
|
||||||
|
let gdid: String = row.get(0);
|
||||||
|
|
||||||
|
if !messagea.is_empty() {
|
||||||
|
match tms_service::feedback(&cookie, &messagea, &gdid).await {
|
||||||
|
Ok(_) => {
|
||||||
|
let update_query = format!(
|
||||||
|
"UPDATE \"{}\" SET isfeedback = 1, a = $1 WHERE code = $2",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
if client.execute(&update_query, &[&messagea, &gdid]).await.is_ok() {
|
||||||
|
success_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
// Log or handle feedback error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(format!("成功反馈 {}/{} 个工单", success_count, total_count))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn feedback_selected_workorders(gdids: Vec<String>, messagea: String) -> Result<String, String> {
|
||||||
|
let username = USERNAME_STORAGE.lock().unwrap().clone().ok_or("用户未登录".to_string())?;
|
||||||
|
let cookie = COOKIE_STORAGE.lock().unwrap().clone().ok_or("未找到登录Cookie")?;
|
||||||
|
let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools";
|
||||||
|
let (mut client, connection) = tokio_postgres::connect(db_url, NoTls)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("数据库连接失败: {}", e))?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = connection.await {
|
||||||
|
eprintln!("connection error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut success_count = 0;
|
||||||
|
let total_count = gdids.len();
|
||||||
|
|
||||||
|
for gdid in gdids {
|
||||||
|
sleep(Duration::from_millis(200)).await;
|
||||||
|
if !messagea.is_empty() {
|
||||||
|
match tms_service::feedback(&cookie, &messagea, &gdid).await {
|
||||||
|
Ok(_) => {
|
||||||
|
let update_query = format!(
|
||||||
|
"UPDATE \"{}\" SET isfeedback = 1, a = $1 WHERE code = $2",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
if client.execute(&update_query, &[&messagea, &gdid]).await.is_ok() {
|
||||||
|
success_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
// Log or handle feedback error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(format!("成功反馈 {}/{} 个工单", success_count, total_count))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn close_workorder(gdid: String) -> Result<(), String> {
|
||||||
|
// Step 1: Call the remote close service
|
||||||
|
let cookie = COOKIE_STORAGE.lock().unwrap().clone().ok_or("未找到登录Cookie")?;
|
||||||
|
tms_service::close(&cookie, &gdid)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("远程关闭失败: {}", e))?;
|
||||||
|
|
||||||
|
// Step 2: If remote close is successful, update the local database
|
||||||
|
let username = USERNAME_STORAGE.lock().unwrap().clone().ok_or("用户未登录".to_string())?;
|
||||||
|
let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools";
|
||||||
|
let (mut client, connection) = tokio_postgres::connect(db_url, NoTls)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("数据库连接失败: {}", e))?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = connection.await {
|
||||||
|
eprintln!("connection error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let query = format!(
|
||||||
|
"UPDATE \"{}\" SET isclose = 1 WHERE code = $1",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
|
||||||
|
client
|
||||||
|
.execute(&query, &[&gdid])
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("关闭工单失败: {}", e))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn close_today_workorders() -> Result<String, String> {
|
||||||
|
let username = USERNAME_STORAGE.lock().unwrap().clone().ok_or("用户未登录".to_string())?;
|
||||||
|
let cookie = COOKIE_STORAGE.lock().unwrap().clone().ok_or("未找到登录Cookie")?;
|
||||||
|
let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools";
|
||||||
|
let (mut client, connection) = tokio_postgres::connect(db_url, NoTls)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("数据库连接失败: {}", e))?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = connection.await {
|
||||||
|
eprintln!("connection error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let query_today_unclosed = format!(
|
||||||
|
"SELECT code FROM \"{}\" WHERE time >= current_date AND isclose = 0",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
|
||||||
|
let rows = client
|
||||||
|
.query(&query_today_unclosed, &[])
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("查询今日未关闭工单失败: {}", e))?;
|
||||||
|
|
||||||
|
let mut success_count = 0;
|
||||||
|
let total_count = rows.len();
|
||||||
|
|
||||||
|
for row in rows {
|
||||||
|
sleep(Duration::from_millis(200)).await;
|
||||||
|
let gdid: String = row.get(0);
|
||||||
|
if tms_service::close(&cookie, &gdid).await.is_ok() {
|
||||||
|
let update_query = format!(
|
||||||
|
"UPDATE \"{}\" SET isclose = 1 WHERE code = $1",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
if client.execute(&update_query, &[&gdid]).await.is_ok() {
|
||||||
|
success_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(format!("成功关闭 {}/{} 个工单", success_count, total_count))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn close_selected_workorders(gdids: Vec<String>) -> Result<String, String> {
|
||||||
|
let username = USERNAME_STORAGE.lock().unwrap().clone().ok_or("用户未登录".to_string())?;
|
||||||
|
let cookie = COOKIE_STORAGE.lock().unwrap().clone().ok_or("未找到登录Cookie")?;
|
||||||
|
let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools";
|
||||||
|
let (mut client, connection) = tokio_postgres::connect(db_url, NoTls)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("数据库连接失败: {}", e))?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = connection.await {
|
||||||
|
eprintln!("connection error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut success_count = 0;
|
||||||
|
let total_count = gdids.len();
|
||||||
|
|
||||||
|
for gdid in gdids {
|
||||||
|
sleep(Duration::from_millis(200)).await;
|
||||||
|
if tms_service::close(&cookie, &gdid).await.is_ok() {
|
||||||
|
let update_query = format!(
|
||||||
|
"UPDATE \"{}\" SET isclose = 1 WHERE code = $1",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
if client.execute(&update_query, &[&gdid]).await.is_ok() {
|
||||||
|
success_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(format!("成功关闭 {}/{} 个工单", success_count, total_count))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn feedback_and_close_today_workorders(messagea: String) -> Result<String, String> {
|
||||||
|
let username = USERNAME_STORAGE.lock().unwrap().clone().ok_or("用户未登录".to_string())?;
|
||||||
|
let cookie = COOKIE_STORAGE.lock().unwrap().clone().ok_or("未找到登录Cookie")?;
|
||||||
|
let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools";
|
||||||
|
let (mut client, connection) = tokio_postgres::connect(db_url, NoTls)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("数据库连接失败: {}", e))?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = connection.await {
|
||||||
|
eprintln!("connection error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let query_today = format!(
|
||||||
|
"SELECT code, isfeedback, isclose FROM \"{}\" WHERE time >= current_date",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
|
||||||
|
let rows = client
|
||||||
|
.query(&query_today, &[])
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("查询今日工单失败: {}", e))?;
|
||||||
|
|
||||||
|
let mut feedback_success_count = 0;
|
||||||
|
let mut close_success_count = 0;
|
||||||
|
let total_count = rows.len();
|
||||||
|
|
||||||
|
for row in rows {
|
||||||
|
sleep(Duration::from_millis(200)).await;
|
||||||
|
let gdid: String = row.get(0);
|
||||||
|
let isfeedback: i32 = row.get(1);
|
||||||
|
let isclose: i32 = row.get(2);
|
||||||
|
|
||||||
|
if isfeedback != 1 && !messagea.is_empty() {
|
||||||
|
if tms_service::feedback(&cookie, &messagea, &gdid).await.is_ok() {
|
||||||
|
let update_query = format!(
|
||||||
|
"UPDATE \"{}\" SET isfeedback = 1, a = $1 WHERE code = $2",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
if client.execute(&update_query, &[&messagea, &gdid]).await.is_ok() {
|
||||||
|
feedback_success_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if isclose != 1 {
|
||||||
|
if tms_service::close(&cookie, &gdid).await.is_ok() {
|
||||||
|
let update_query = format!(
|
||||||
|
"UPDATE \"{}\" SET isclose = 1 WHERE code = $1",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
if client.execute(&update_query, &[&gdid]).await.is_ok() {
|
||||||
|
close_success_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(format!("成功反馈 {}/{} 个, 成功关闭 {}/{} 个", feedback_success_count, total_count, close_success_count, total_count))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
|
pub fn run() {
|
||||||
|
tauri::Builder::default()
|
||||||
|
.plugin(tauri_plugin_opener::init())
|
||||||
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
login,
|
||||||
|
get_cookie,
|
||||||
|
get_dashboard_username,
|
||||||
|
get_workorders,
|
||||||
|
create_ticket_command,
|
||||||
|
insert_workorder,
|
||||||
|
feedback_workorder,
|
||||||
|
feedback_today_workorders,
|
||||||
|
feedback_selected_workorders,
|
||||||
|
close_workorder,
|
||||||
|
close_today_workorders,
|
||||||
|
close_selected_workorders,
|
||||||
|
feedback_and_close_today_workorders
|
||||||
|
])
|
||||||
|
.run(tauri::generate_context!())
|
||||||
|
.expect("error while running tauri application");
|
||||||
|
}
|
||||||
7
src-tauri/src/main.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
tms_tools_lib::run()
|
||||||
|
}
|
||||||
|
|
||||||
35
src-tauri/tauri.conf.json
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
|
"productName": "tms_tools",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"identifier": "com.tms_tools.app",
|
||||||
|
"build": {
|
||||||
|
"beforeDevCommand": "pnpm dev",
|
||||||
|
"devUrl": "http://localhost:1420",
|
||||||
|
"beforeBuildCommand": "pnpm build",
|
||||||
|
"frontendDist": "../dist"
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"windows": [
|
||||||
|
{
|
||||||
|
"title": "tms_tools",
|
||||||
|
"width": 800,
|
||||||
|
"height": 600
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"security": {
|
||||||
|
"csp": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bundle": {
|
||||||
|
"active": true,
|
||||||
|
"targets": "all",
|
||||||
|
"icon": [
|
||||||
|
"icons/32x32.png",
|
||||||
|
"icons/128x128.png",
|
||||||
|
"icons/128x128@2x.png",
|
||||||
|
"icons/icon.icns",
|
||||||
|
"icons/icon.ico"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src-tauri/tms_service/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "tms_service"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
reqwest = "0.12.22"
|
||||||
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
|
openai = { path = "../openai" }
|
||||||
180
src-tauri/tms_service/src/lib.rs
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
use reqwest::cookie::Jar;
|
||||||
|
use reqwest::header;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct ApiResponse {
|
||||||
|
msg: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add(left: u64, right: u64) -> u64 {
|
||||||
|
left + right
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn create_ticket(cookie: &str, n2p: &str, massageQ: &str, wx: &str) -> Result<String, reqwest::Error> {
|
||||||
|
println!("cookie={},n2n={},问题={}, 微信={}", cookie, n2p, massageQ, wx);
|
||||||
|
|
||||||
|
// 1. Create a cookie jar and a single client for all requests
|
||||||
|
let jar = Arc::new(Jar::default());
|
||||||
|
let initial_url: reqwest::Url = "http://c.baobaot.com".parse().unwrap();
|
||||||
|
// The cookie string can contain multiple cookies separated by ';'.
|
||||||
|
// We need to add them one by one.
|
||||||
|
for part in cookie.split(';') {
|
||||||
|
jar.add_cookie_str(part.trim(), &initial_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.cookie_provider(jar.clone())
|
||||||
|
.build()?;
|
||||||
|
println!("开始获取平台id");
|
||||||
|
// 2. Get the edit page URL
|
||||||
|
let url = format!("http://c.baobaot.com/admin/etms/n2nip?n2nip=&cinemacode={}", n2p);
|
||||||
|
let res = client.get(&url).send().await?;
|
||||||
|
let body_bytes = res.bytes().await?;
|
||||||
|
let body = String::from_utf8_lossy(&body_bytes).to_string();
|
||||||
|
|
||||||
|
println!("源码获取完成");
|
||||||
|
|
||||||
|
let system_prompt = "告诉我编辑按钮的链接,只要告诉我链接的url就可以,不要说其他的任何内容";
|
||||||
|
let edit_page_url = openai::ask_openai(&body, system_prompt).await?;
|
||||||
|
println!("平台id{}", edit_page_url);
|
||||||
|
|
||||||
|
// 3. Visit the edit page to get its source
|
||||||
|
let res2 = client.get(&edit_page_url).send().await?;
|
||||||
|
let body2_bytes = res2.bytes().await?;
|
||||||
|
let body2 = String::from_utf8_lossy(&body2_bytes).to_string();
|
||||||
|
|
||||||
|
// 4. Get the TMS config URL
|
||||||
|
let system_prompt2 = "告诉我TMS配置按钮的链接,只要告诉我链接的url就可以,不要说其他的任何内容";
|
||||||
|
let tms_config_url = openai::ask_openai(&body2, system_prompt2).await?;
|
||||||
|
println!("tms配置链接{}", tms_config_url);
|
||||||
|
|
||||||
|
// 5. Visit the TMS config URL to get the token
|
||||||
|
let res3 = client.get(&tms_config_url).send().await?;
|
||||||
|
let body3_bytes = res3.bytes().await?;
|
||||||
|
let body3 = String::from_utf8_lossy(&body3_bytes).to_string();
|
||||||
|
|
||||||
|
let system_prompt3 = "告诉我权限认证(token)的值,只要告诉我对应的值就行,不要说其他的任何内容";
|
||||||
|
let token = openai::ask_openai(&body3, system_prompt3).await?;
|
||||||
|
println!("token={}", token);
|
||||||
|
|
||||||
|
// 6. Visit the final URL to get the session cookies
|
||||||
|
let final_url = format!("https://c.baobaot.com/cinema/workorder?token={}", token);
|
||||||
|
let _final_res = client.get(&final_url).send().await?;
|
||||||
|
|
||||||
|
// 7. Now the jar should contain all necessary cookies.
|
||||||
|
// We can proceed to create the work order.
|
||||||
|
|
||||||
|
let form_data = &[
|
||||||
|
("type", "99"),
|
||||||
|
("describe", massageQ),
|
||||||
|
("input_file[]", ""),
|
||||||
|
("contact_way", "wx"),
|
||||||
|
("contact", wx),
|
||||||
|
("visit_way", "1"),
|
||||||
|
];
|
||||||
|
|
||||||
|
let post_url = "https://c.baobaot.com/cinema/workorder/ajax_create";
|
||||||
|
|
||||||
|
let res = client.post(post_url).form(form_data).send().await?;
|
||||||
|
let response_bytes = res.bytes().await?;
|
||||||
|
let response_body = String::from_utf8_lossy(&response_bytes).to_string();
|
||||||
|
|
||||||
|
match serde_json::from_str::<ApiResponse>(&response_body) {
|
||||||
|
Ok(api_response) => {
|
||||||
|
if api_response.msg != "提交成功" {
|
||||||
|
return Ok(response_body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
return Ok(response_body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8. Get new cookie before fetching work order list
|
||||||
|
let final_url = format!("https://c.baobaot.com/cinema/workorder?token={}", token);
|
||||||
|
let _final_res = client.get(&final_url).send().await?;
|
||||||
|
|
||||||
|
// 9. Get the work order page to find the latest order
|
||||||
|
let workorder_url = "https://c.baobaot.com/cinema/workorder";
|
||||||
|
let workorder_res = client.get(workorder_url).send().await?;
|
||||||
|
let workorder_bytes = workorder_res.bytes().await?;
|
||||||
|
let workorder_html = String::from_utf8_lossy(&workorder_bytes).to_string();
|
||||||
|
|
||||||
|
let system_prompt_details = "找到最新的一个工单所对应的详情按钮的url地址中id的值,只要告诉我对应的值就可以,不要说其他任何内容";
|
||||||
|
let details_url = openai::ask_openai(&workorder_html, system_prompt_details).await?;
|
||||||
|
|
||||||
|
Ok(details_url)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn feedback(cookie: &str, messageA: &str, gdID: &str) -> Result<String, reqwest::Error> {
|
||||||
|
// 1. Create a cookie jar and a single client for all requests
|
||||||
|
let jar = Arc::new(Jar::default());
|
||||||
|
let initial_url: reqwest::Url = "https://c.baobaot.com".parse().unwrap();
|
||||||
|
// The cookie string can contain multiple cookies separated by ';'.
|
||||||
|
// We need to add them one by one.
|
||||||
|
for part in cookie.split(';') {
|
||||||
|
jar.add_cookie_str(part.trim(), &initial_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.cookie_provider(jar.clone())
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
// 2. Prepare form data
|
||||||
|
let form_data = &[
|
||||||
|
("message", messageA),
|
||||||
|
("input_file[]", ""),
|
||||||
|
("id", gdID),
|
||||||
|
("act", "confirm_feedback"),
|
||||||
|
];
|
||||||
|
|
||||||
|
// 3. Send POST request
|
||||||
|
let post_url = "https://c.baobaot.com/admin/workorder/ajax_update";
|
||||||
|
let res = client.post(post_url).form(form_data).send().await?;
|
||||||
|
let response_bytes = res.bytes().await?;
|
||||||
|
let response_body = String::from_utf8_lossy(&response_bytes).to_string();
|
||||||
|
|
||||||
|
Ok(response_body)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn close(cookie: &str, gdID: &str) -> Result<String, reqwest::Error> {
|
||||||
|
// 1. Create a cookie jar and a single client for all requests
|
||||||
|
let jar = Arc::new(Jar::default());
|
||||||
|
let initial_url: reqwest::Url = "https://c.baobaot.com".parse().unwrap();
|
||||||
|
// The cookie string can contain multiple cookies separated by ';'.
|
||||||
|
// We need to add them one by one.
|
||||||
|
for part in cookie.split(';') {
|
||||||
|
jar.add_cookie_str(part.trim(), &initial_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.cookie_provider(jar.clone())
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
// 2. Prepare form data
|
||||||
|
let form_data = &[
|
||||||
|
("id", gdID),
|
||||||
|
("act", "close_workorder"),
|
||||||
|
];
|
||||||
|
|
||||||
|
// 3. Send POST request
|
||||||
|
let post_url = "https://c.baobaot.com/admin/workorder/ajax_update";
|
||||||
|
let res = client.post(post_url).form(form_data).send().await?;
|
||||||
|
let response_bytes = res.bytes().await?;
|
||||||
|
let response_body = String::from_utf8_lossy(&response_bytes).to_string();
|
||||||
|
|
||||||
|
Ok(response_body)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
let result = add(2, 2);
|
||||||
|
assert_eq!(result, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/App.vue
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<template>
|
||||||
|
<router-view />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html,
|
||||||
|
body,
|
||||||
|
#app {
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
background-color: #f0f2f5; /* 浅色背景 */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
102
src/components/Login.vue
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<template>
|
||||||
|
<div class="login-container">
|
||||||
|
<el-card class="login-card">
|
||||||
|
<template #header>
|
||||||
|
<div class="card-header">
|
||||||
|
<span>登录</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-form
|
||||||
|
ref="loginFormRef"
|
||||||
|
:model="loginForm"
|
||||||
|
:rules="loginRules"
|
||||||
|
label-width="80px"
|
||||||
|
>
|
||||||
|
<el-form-item label="用户名" prop="username">
|
||||||
|
<el-input
|
||||||
|
v-model="loginForm.username"
|
||||||
|
placeholder="请输入用户名"
|
||||||
|
></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="密码" prop="password">
|
||||||
|
<el-input
|
||||||
|
v-model="loginForm.password"
|
||||||
|
type="password"
|
||||||
|
placeholder="请输入密码"
|
||||||
|
show-password
|
||||||
|
></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="handleLogin">登录</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</el-card>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, reactive } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const loginFormRef = ref(null)
|
||||||
|
|
||||||
|
const loginForm = reactive({
|
||||||
|
username: '',
|
||||||
|
password: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
const loginRules = reactive({
|
||||||
|
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||||
|
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleLogin = () => {
|
||||||
|
loginFormRef.value.validate(async (valid) => {
|
||||||
|
if (valid) {
|
||||||
|
try {
|
||||||
|
const result = await invoke('login', {
|
||||||
|
username: loginForm.username,
|
||||||
|
password: loginForm.password,
|
||||||
|
})
|
||||||
|
if (result.success) {
|
||||||
|
ElMessage.success(result.message)
|
||||||
|
router.push('/workorder')
|
||||||
|
} else {
|
||||||
|
ElMessage.error(result.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(`登录失败: ${error}`)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ElMessage.error('请输入用户名和密码')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.login-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-card {
|
||||||
|
width: 450px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-button {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
14
src/main.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { createApp } from "vue";
|
||||||
|
import App from "./App.vue";
|
||||||
|
import router from './router';
|
||||||
|
import ElementPlus from 'element-plus'
|
||||||
|
import 'element-plus/dist/index.css'
|
||||||
|
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||||
|
|
||||||
|
const app = createApp(App)
|
||||||
|
|
||||||
|
app.use(router)
|
||||||
|
app.use(ElementPlus, {
|
||||||
|
locale: zhCn,
|
||||||
|
})
|
||||||
|
app.mount("#app");
|
||||||
27
src/router/index.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
|
import Login from '../components/Login.vue';
|
||||||
|
import WorkOrder from '../service/workorder.vue';
|
||||||
|
|
||||||
|
const routes = [
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
redirect: '/login',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/login',
|
||||||
|
name: 'Login',
|
||||||
|
component: Login,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/workorder',
|
||||||
|
name: 'WorkOrder',
|
||||||
|
component: WorkOrder,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const router = createRouter({
|
||||||
|
history: createWebHistory(),
|
||||||
|
routes,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
442
src/service/workorder.vue
Normal file
@@ -0,0 +1,442 @@
|
|||||||
|
<template>
|
||||||
|
<div class="page-container">
|
||||||
|
<el-row :gutter="20">
|
||||||
|
<!-- 左侧表单区域 -->
|
||||||
|
<el-col :xs="24" :sm="24" :md="10">
|
||||||
|
<el-card class="box-card">
|
||||||
|
<template #header>
|
||||||
|
<div class="card-header">
|
||||||
|
<span>工单操作</span>
|
||||||
|
<span v-if="username" class="username-display">欢迎, {{ username }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-form label-width="80px" label-position="left">
|
||||||
|
<el-form-item label="影院编码">
|
||||||
|
<el-input v-model="form.n2nip" :disabled="isCreating" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="问题描述">
|
||||||
|
<el-input v-model="form.messageQ" type="textarea" :rows="3" :disabled="isCreating" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="联系方式">
|
||||||
|
<el-radio-group v-model="form.contact_way" :disabled="isCreating">
|
||||||
|
<el-radio label="wx">微信</el-radio>
|
||||||
|
<el-radio label="mobile">手机</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="号码">
|
||||||
|
<el-input v-model="form.contact" :disabled="isCreating" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="工号">
|
||||||
|
<el-input v-model="form.gh" disabled />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="工单ID">
|
||||||
|
<el-input v-model="form.gdID" :disabled="isCreating" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="反馈">
|
||||||
|
<el-input v-model="form.messageA" type="textarea" :rows="3" :disabled="isCreating" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<div class="form-buttons">
|
||||||
|
<el-button type="primary" @click="createWorkOrder" :disabled="isCreating">创建工单</el-button>
|
||||||
|
<el-button type="success" @click="feedbackSingleWorkOrder" :disabled="isCreating">反馈工单</el-button>
|
||||||
|
<el-button type="danger" @click="closeSingleWorkOrder" :disabled="isCreating">关闭工单</el-button>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<div class="form-buttons">
|
||||||
|
<el-button type="success" @click="feedbackTodaysOrders" :disabled="isCreating">反馈今日工单</el-button>
|
||||||
|
<el-button type="danger" @click="closeTodaysOrders" :disabled="isCreating">关闭今日工单</el-button>
|
||||||
|
<el-button type="warning" @click="feedbackAndCloseTodaysOrders" :disabled="isCreating">反馈并关闭今日工单</el-button>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="日志">
|
||||||
|
<el-input type="textarea" :rows="4" v-model="log" disabled />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</el-card>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<!-- 右侧工单列表区域 -->
|
||||||
|
<el-col :xs="24" :sm="24" :md="14">
|
||||||
|
<el-card class="box-card">
|
||||||
|
<div class="action-bar">
|
||||||
|
<el-button type="primary" @click="selectAll">全选</el-button>
|
||||||
|
<el-select v-model="workOrderRange" placeholder="选择范围" size="small" @change="fetchWorkOrders" style="width: 120px;">
|
||||||
|
<el-option label="今日工单" value="today"></el-option>
|
||||||
|
<el-option label="本月工单" value="month"></el-option>
|
||||||
|
</el-select>
|
||||||
|
<el-select v-model="feedbackFilter" placeholder="反馈状态" size="small" clearable style="width: 120px;">
|
||||||
|
<el-option label="已反馈" :value="1"></el-option>
|
||||||
|
<el-option label="未反馈" :value="0"></el-option>
|
||||||
|
</el-select>
|
||||||
|
<el-select v-model="closeFilter" placeholder="关闭状态" size="small" clearable style="width: 120px;">
|
||||||
|
<el-option label="已关闭" :value="1"></el-option>
|
||||||
|
<el-option label="未关闭" :value="0"></el-option>
|
||||||
|
</el-select>
|
||||||
|
<div class="order-count">
|
||||||
|
<span>工单总数: {{ filteredOrderList.length }}</span>
|
||||||
|
<el-button type="primary" icon="Refresh" circle size="small" class="ml-2" @click="fetchWorkOrders"></el-button>
|
||||||
|
</div>
|
||||||
|
<div class="action-buttons">
|
||||||
|
<el-button type="success" @click="feedbackSelected">反馈选中</el-button>
|
||||||
|
<el-button type="warning" @click="closeSelected">结束选中</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="loading" class="loading-text">正在加载工单数据...</div>
|
||||||
|
<div v-else-if="filteredOrderList.length === 0" class="loading-text">暂无工单数据</div>
|
||||||
|
<div v-else class="order-list">
|
||||||
|
<el-card v-for="order in filteredOrderList" :key="order.gdid" class="order-item">
|
||||||
|
<template #header>
|
||||||
|
<div class="order-header">
|
||||||
|
<span>工单ID: {{ order.gdid }}</span>
|
||||||
|
<span>影院编码: {{ order.n2n }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div class="order-body">
|
||||||
|
<p><strong>问题描述:</strong> {{ order.messageq }}</p>
|
||||||
|
<p><strong>处理结果:</strong> {{ order.messagea || '暂无处理结果' }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="order-footer">
|
||||||
|
<el-tag :type="order.iscreate === 0 ? 'success' : 'warning'">{{ order.iscreate === 0 ? '已创建' : '未创建' }}</el-tag>
|
||||||
|
<el-tag :type="order.isfeedback === 1 ? 'success' : 'warning'">{{ order.isfeedback === 1 ? '已反馈' : '未反馈' }}</el-tag>
|
||||||
|
<el-tag :type="order.isclose === 1 ? 'success' : 'warning'">{{ order.isclose === 1 ? '已关闭' : '未关闭' }}</el-tag>
|
||||||
|
<el-checkbox :model-value="selectedOrders.has(order.gdid)" @change="toggleSelection(order.gdid)" />
|
||||||
|
</div>
|
||||||
|
</el-card>
|
||||||
|
</div>
|
||||||
|
</el-card>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, reactive, onMounted, computed } from 'vue';
|
||||||
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
|
||||||
|
const username = ref('');
|
||||||
|
const isCreating = ref(false);
|
||||||
|
const form = reactive({
|
||||||
|
n2nip: '',
|
||||||
|
messageQ: '',
|
||||||
|
contact_way: 'mobile',
|
||||||
|
contact: '',
|
||||||
|
gh: '02',
|
||||||
|
gdID: '',
|
||||||
|
messageA: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const log = ref('');
|
||||||
|
const workOrderRange = ref('today'); // 'today' or 'month'
|
||||||
|
const feedbackFilter = ref(null); // 1 for feedbacked, 0 for not, null for all
|
||||||
|
const closeFilter = ref(null); // 1 for closed, 0 for not, null for all
|
||||||
|
const loading = ref(true);
|
||||||
|
const orderList = ref([]);
|
||||||
|
const selectedOrders = ref(new Set());
|
||||||
|
|
||||||
|
const filteredOrderList = computed(() => {
|
||||||
|
return orderList.value.filter(order => {
|
||||||
|
const feedbackMatch = feedbackFilter.value == null || order.isfeedback === feedbackFilter.value;
|
||||||
|
const closeMatch = closeFilter.value == null || order.isclose === closeFilter.value;
|
||||||
|
return feedbackMatch && closeMatch;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
async function fetchWorkOrders() {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const workOrderData = await invoke('get_workorders', { range: workOrderRange.value });
|
||||||
|
orderList.value = workOrderData.orders;
|
||||||
|
} catch (e) {
|
||||||
|
log.value += `获取工单列表失败: ${e}\n`;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
const name = await invoke('get_dashboard_username');
|
||||||
|
username.value = name;
|
||||||
|
} catch (e) {
|
||||||
|
log.value += `获取用户名失败: ${e}\n`;
|
||||||
|
}
|
||||||
|
await fetchWorkOrders();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function createWorkOrder() {
|
||||||
|
isCreating.value = true;
|
||||||
|
log.value = '开始创建工单...\n';
|
||||||
|
try {
|
||||||
|
const massageQ = `${form.messageQ}${form.gh}`;
|
||||||
|
log.value += `调用 create_ticket...\n参数: n2p=${form.n2nip}, massageQ=${massageQ}, wx=${form.contact}\n`;
|
||||||
|
|
||||||
|
const code = await invoke('create_ticket_command', {
|
||||||
|
n2p: form.n2nip,
|
||||||
|
massageQ: massageQ,
|
||||||
|
wx: form.contact,
|
||||||
|
});
|
||||||
|
|
||||||
|
log.value += `工单创建请求成功,返回代码: ${code}\n`;
|
||||||
|
log.value += '正在将工单写入数据库...\n';
|
||||||
|
|
||||||
|
await invoke('insert_workorder', {
|
||||||
|
code: code,
|
||||||
|
n2n: form.n2nip,
|
||||||
|
q: form.messageQ,
|
||||||
|
a: form.messageA,
|
||||||
|
});
|
||||||
|
|
||||||
|
log.value += '工单成功写入数据库。\n';
|
||||||
|
await fetchWorkOrders();
|
||||||
|
} catch (error) {
|
||||||
|
log.value += `创建工单过程中出错: ${error}\n`;
|
||||||
|
} finally {
|
||||||
|
isCreating.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSelection(gdid) {
|
||||||
|
if (selectedOrders.value.has(gdid)) {
|
||||||
|
selectedOrders.value.delete(gdid);
|
||||||
|
} else {
|
||||||
|
selectedOrders.value.add(gdid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectAll() {
|
||||||
|
const allIds = orderList.value.map(order => order.gdid);
|
||||||
|
const allSelected = allIds.every(id => selectedOrders.value.has(id));
|
||||||
|
|
||||||
|
if (allSelected) {
|
||||||
|
selectedOrders.value.clear();
|
||||||
|
} else {
|
||||||
|
allIds.forEach(id => selectedOrders.value.add(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function feedbackSingleWorkOrder() {
|
||||||
|
if (!form.gdID) {
|
||||||
|
log.value += '请输入要反馈的工单ID\n';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.value += `开始反馈工单 ${form.gdID}...\n`;
|
||||||
|
try {
|
||||||
|
await invoke('feedback_workorder', { gdid: form.gdID, messagea: form.messageA });
|
||||||
|
log.value += `工单 ${form.gdID} 反馈成功。\n`;
|
||||||
|
await fetchWorkOrders();
|
||||||
|
} catch (error) {
|
||||||
|
log.value += `反馈工单 ${form.gdID} 出错: ${error}\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function closeSingleWorkOrder() {
|
||||||
|
if (!form.gdID) {
|
||||||
|
log.value += '请输入要关闭的工单ID\n';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.value += `开始关闭工单 ${form.gdID}...\n`;
|
||||||
|
try {
|
||||||
|
await invoke('close_workorder', { gdid: form.gdID });
|
||||||
|
log.value += `工单 ${form.gdID} 关闭成功。\n`;
|
||||||
|
await fetchWorkOrders();
|
||||||
|
} catch (error) {
|
||||||
|
log.value += `关闭工单出错: ${error}\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function feedbackSelected() {
|
||||||
|
if (selectedOrders.value.size === 0) {
|
||||||
|
log.value += '请先选择要反馈的工单。\n';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!form.messageA) {
|
||||||
|
log.value += '请在左侧表单填写反馈内容。\n';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.value += `开始批量反馈 ${selectedOrders.value.size} 个工单...\n`;
|
||||||
|
try {
|
||||||
|
const gdids = Array.from(selectedOrders.value);
|
||||||
|
const result = await invoke('feedback_selected_workorders', { gdids, messagea: form.messageA });
|
||||||
|
log.value += `${result}\n`;
|
||||||
|
await fetchWorkOrders();
|
||||||
|
selectedOrders.value.clear();
|
||||||
|
} catch (error) {
|
||||||
|
log.value += `批量反馈出错: ${error}\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function closeSelected() {
|
||||||
|
if (selectedOrders.value.size === 0) {
|
||||||
|
log.value += '请先选择要关闭的工单。\n';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.value += `开始批量关闭 ${selectedOrders.value.size} 个工单...\n`;
|
||||||
|
try {
|
||||||
|
const gdids = Array.from(selectedOrders.value);
|
||||||
|
const result = await invoke('close_selected_workorders', { gdids });
|
||||||
|
log.value += `${result}\n`;
|
||||||
|
await fetchWorkOrders();
|
||||||
|
selectedOrders.value.clear();
|
||||||
|
} catch (error) {
|
||||||
|
log.value += `批量关闭出错: ${error}\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function feedbackTodaysOrders() {
|
||||||
|
if (!form.messageA) {
|
||||||
|
log.value += '请在左侧表单填写反馈内容。\n';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.value += `开始反馈今日所有工单...\n`;
|
||||||
|
try {
|
||||||
|
const result = await invoke('feedback_today_workorders', { messagea: form.messageA });
|
||||||
|
log.value += `${result}\n`;
|
||||||
|
await fetchWorkOrders();
|
||||||
|
} catch (error) {
|
||||||
|
log.value += `反馈今日工单出错: ${error}\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function closeTodaysOrders() {
|
||||||
|
log.value += `开始关闭今日所有工单...\n`;
|
||||||
|
try {
|
||||||
|
const result = await invoke('close_today_workorders');
|
||||||
|
log.value += `${result}\n`;
|
||||||
|
await fetchWorkOrders();
|
||||||
|
} catch (error) {
|
||||||
|
log.value += `关闭今日工单出错: ${error}\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function feedbackAndCloseTodaysOrders() {
|
||||||
|
if (!form.messageA) {
|
||||||
|
log.value += '请在左侧表单填写反馈内容。\n';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.value += `开始反馈并关闭今日所有工单...\n`;
|
||||||
|
try {
|
||||||
|
const result = await invoke('feedback_and_close_today_workorders', { messagea: form.messageA });
|
||||||
|
log.value += `${result}\n`;
|
||||||
|
await fetchWorkOrders();
|
||||||
|
} catch (error) {
|
||||||
|
log.value += `反馈并关闭今日工单出错: ${error}\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.page-container {
|
||||||
|
padding: 20px;
|
||||||
|
background-color: #f5f7fa;
|
||||||
|
min-height: 100vh;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box-card {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.username-display {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #606266;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-buttons {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-buttons .el-button {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-bar {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 15px;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.days-ago-container,
|
||||||
|
.order-count,
|
||||||
|
.action-buttons,
|
||||||
|
.auth-buttons {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ml-2 {
|
||||||
|
margin-left: 8px; /* Kept for compatibility if needed elsewhere */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.loading-text {
|
||||||
|
padding: 40px;
|
||||||
|
text-align: center;
|
||||||
|
color: #95a5a6;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-list {
|
||||||
|
max-height: calc(100vh - 350px); /* Adjust height dynamically */
|
||||||
|
overflow-y: auto;
|
||||||
|
padding-right: 10px; /* For scrollbar */
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-item {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-body p {
|
||||||
|
margin: 8px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 15px;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive adjustments */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.el-col {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-bar {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-bar > div {
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-list {
|
||||||
|
max-height: none; /* Allow list to expand on mobile */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
31
vite.config.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { defineConfig } from "vite";
|
||||||
|
import vue from "@vitejs/plugin-vue";
|
||||||
|
|
||||||
|
const host = process.env.TAURI_DEV_HOST;
|
||||||
|
|
||||||
|
// https://vitejs.dev/config/
|
||||||
|
export default defineConfig(async () => ({
|
||||||
|
plugins: [vue()],
|
||||||
|
|
||||||
|
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
|
||||||
|
//
|
||||||
|
// 1. prevent vite from obscuring rust errors
|
||||||
|
clearScreen: false,
|
||||||
|
// 2. tauri expects a fixed port, fail if that port is not available
|
||||||
|
server: {
|
||||||
|
port: 1420,
|
||||||
|
strictPort: true,
|
||||||
|
host: host || false,
|
||||||
|
hmr: host
|
||||||
|
? {
|
||||||
|
protocol: "ws",
|
||||||
|
host,
|
||||||
|
port: 1421,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
watch: {
|
||||||
|
// 3. tell vite to ignore watching `src-tauri`
|
||||||
|
ignored: ["**/src-tauri/**"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||