Skip to content

Commit

Permalink
feat: add select user and buy listory
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyutim committed Jun 8, 2023
1 parent 4b8f790 commit ae5719a
Show file tree
Hide file tree
Showing 14 changed files with 375 additions and 63 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

[点击查看下载页面](https://github.com/shiyutim/tickets/releases),下载对应的版本即可。

自己编译(需要 rust、node 环境):
## 编译(需要 rust、node 环境):

1. `yarn` 安装依赖
2. `yarn tauri build` 打包程序。生成的程序在 src-tauri/target/release 下。
1. 安装 rust `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` [rust 官网](https://www.rust-lang.org/tools/install)
2. 安装 node [node 官网](https://nodejs.org/en)
3. 运行 `yarn` 安装依赖
4. 运行 `yarn tauri build` 打包程序。生成的程序在 src-tauri/target/release 下。

## 使用

Expand All @@ -28,15 +30,12 @@ F12 打开控制台,在 network 下,找到对应的 http 请求,然后找

## 注意事项

1. 需要在[大麦移动端](https://m.damai.cn/damai/home/index.html)进入对应的商品页面,如果支持购买,则此软件支持。
2. **目前购买票数需要跟实名观演人个数一致**,后续会优化
3. 提示 session 失效等,需要更换 cookie(不一定需要重新登录,重新进入大麦页面获取即可)
4. 尽量不要多次重复尝试下订单,因为阿里系产品有风控,可能会限制账号或 ip 等。如果多次尝试导致出现账号无法登录的情况,切换个浏览器即可。
5. **不支持选座**
6. FAIL_SYS_USER_VALIDATE 类似的提示可能当前浏览器已经被限制,目前需要切换个浏览器。
1. 提示 session 失效等,需要更换 cookie(不一定需要重新登录,重新进入大麦页面获取即可)
2. 尽量不要多次重复尝试下订单,因为阿里系产品有风控,可能会限制账号或 ip 等。如果多次尝试导致出现账号无法登录的情况,切换个浏览器即可。
3. **不支持选座**
4. FAIL_SYS_USER_VALIDATE 类似的提示可能当前浏览器已经被限制,目前需要切换个浏览器。

## TODO

1. 可选择观演人
2. 选座支持
3. 其他平台支持
1. 选座支持
2. 其他平台支持
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"@tauri-apps/api": "^1.3.0",
"dayjs": "^1.11.8",
"sass": "^1.62.1",
"vue": "^3.2.45"
"vue": "^3.2.45",
"vuex": "^4.0.2"
},
"devDependencies": {
"@tauri-apps/cli": "^1.3.1",
Expand Down
40 changes: 40 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,53 @@ async fn create_order_res(
Ok(res)
}

#[tauri::command]
fn get_user_list(t: usize, sign: &str, cookie: &str, data: &str) -> String {
let res = get_user_list_res(t, sign, cookie, data);

match res {
Err(e) => String::from("数据观演人信息错误"),
Ok(data) => data,
}
}

#[tokio::main]
async fn get_user_list_res(
t: usize,
sign: &str,
cookie: &str,
data: &str,
) -> Result<String, Box<dyn Error>> {
let url = format!("https://mtop.damai.cn/h5/mtop.damai.wireless.user.customerlist.get/2.0/?jsv=2.7.2&appKey=12574478&t={}&sign={}&type=originaljson&dataType=json&v=2.0&H5Request=true&AntiCreep=true&AntiFlood=true&api=mtop.damai.wireless.user.customerlist.get&method=GET&hasToast=true&needTbLogin=true&data={}", t, sign, data);

let mut headers = get_common_headers();
headers.insert(
"content-type",
"application/x-www-form-urlencoded".parse().unwrap(),
);
headers.insert(header::COOKIE, cookie.parse().unwrap());

let client = reqwest::Client::new();
let res = client
.get(url)
.headers(headers)
.timeout(Duration::from_secs(3))
.send()
.await?
.text()
.await?;

Ok(res)
}

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
get_product_info,
get_ticket_list,
get_ticket_detail,
create_order,
get_user_list,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
50 changes: 50 additions & 0 deletions src/components/dm/BuyHistory.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<script setup lang="js">
import { useStore } from 'vuex'
import { onMounted , computed} from 'vue';
import dayjs from 'dayjs'
const store = useStore()
const format = `YYYY-MM-DD HH:mm:ss`
const historyList = computed(() => store.state.dm.buyHistory.reverse())
// TODO 显示优化
function init() {
// 加载本地数据
let storageData = localStorage.getItem('buyHistory')
storageData = storageData ? JSON.parse(storageData) : []
// 写入 vuex 中
store.commit("pushBuyHistory", storageData)
}
function getDesc(item) {
return `开始: ${dayjs(item.startTime).format(format)} 结束: ${dayjs(item.endTime).format(format)} 花费: ${item.diff}ms`
}
onMounted(() => {
init()
})
</script>

<template>
<div>
<a-collapse :default-active-key="[]">
<a-collapse-item
header="抢票记录(只保存在本地,卸载即消失)"
key="1"
>
<a-list :max-height="300">
<a-list-item v-for="(item, idx) in historyList" :key="idx">
<a-list-item-meta
:title="item.message"
:description="getDesc(item)"
>
</a-list-item-meta>
</a-list-item>
</a-list>
</a-collapse-item>
</a-collapse>
</div>
</template>
24 changes: 20 additions & 4 deletions src/components/dm/Form.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<script setup lang="js">
import { reactive, ref, watch } from 'vue';
import { reactive, watch } from 'vue';
import { getQueryString } from '../../../utils/common';
import { Message, Notification } from "@arco-design/web-vue";
import { Message } from "@arco-design/web-vue";
import { useStore } from 'vuex';
import {
getToken,
} from "../../../utils/dm/index.js";
const store = useStore();
const form = reactive({
cookie: "",
Expand All @@ -27,7 +33,17 @@ const props = defineProps({
})
function handleSubmit(e) {
props.handleSubmit(e)
if(e.errors) {
return
}
store.commit('addForm', {
...e.values,
cookie: e.values.cookie.trim(),
// 根据 cookie 解析 token,用来生成 t 和 sign
token: getToken(e.values.cookie.trim())
})
props.handleSubmit()
}
</script>

Expand Down Expand Up @@ -78,7 +94,7 @@ function handleSubmit(e) {
</a-form-item>

<a-form-item>
<a-button html-type="submit">获取商品信息</a-button>
<a-button html-type="submit">确定</a-button>
</a-form-item>
</a-form>
</section>
Expand Down
Loading

0 comments on commit ae5719a

Please sign in to comment.