This commit is contained in:
Putoo
2026-05-27 18:26:50 +08:00
parent 36a7575990
commit 0d5443ef36
28 changed files with 1043 additions and 25 deletions

View File

@@ -0,0 +1,12 @@
export class LocalStorageHelper {
/**npc相关 */
private static key: string = 'OnNpc';
public static GetOnNpc() {
return LocalStorageExtend.Get(this.key);
}
public static SetOnNpc(npcId: String) {
LocalStorageExtend.Set(this.key, npcId);
}
}

View File

@@ -0,0 +1 @@
<template></template>

View File

@@ -0,0 +1 @@
<template></template>

View File

@@ -20,7 +20,7 @@
</div>
<div class="content">
<div class="item" v-for="item in npcData">
<Abar href="">{{ item.npcName }}{{ item.tips }}</Abar>
<Abar :href='"/npc?npc="+item.npcId'>{{ item.npcName }}{{ item.tips }}</Abar>
</div>
</div>

View File

@@ -0,0 +1,49 @@
<template>
<div class="content">
<div class="common">
{{ data.npcName }}
</div>
<div class="common">
{{ data.story }}
</div>
</div>
<div class="content">
<div class="item" v-for="item in data.bus">
<Abar :href="item.url">{{ item.name }}</Abar>
</div>
</div>
</template>
<script setup lang="ts">
definePageMeta({
layout: layout.default,
middleware: 'page-loading'
})
const data = ref<any>({});
onMounted(async () => {
try {
await BindData();
}
finally {
PageLoading.Close();
}
})
const BindData = async (): Promise<void> => {
let npc = PageExtend.QueryString("npc");
let result = await MapService.GetNpcInfo(Number(npc));
if (result.code == 0) {
data.value = result.data;
LocalStorageHelper.SetOnNpc(npc);//存储当前进的npc信息
}
else {
MessageExtend.ShowDialogEvent("提示", result.msg, () => {
PageExtend.Redirect("/map");
});
}
};
</script>

100
Web/src/pages/store/buy.vue Normal file
View File

@@ -0,0 +1,100 @@
<template>
<div class="content">
{{ npcName }}:看看有没有你需要的?
</div>
<div class="content">
<div class="item" v-for="(item, index) in data" :key="index">
{{ PageExtend.GetPageIndex(currentPage, 10, index + 1) }}.
<Abar :href='"/prop/equ?id=" + item.parameter' v-if="item.type == 'Equ'">
{{ item.name }}({{ GameTool.GetCurrencyNameAll(item.price, item.payType) }})</Abar>
<Abar :href='"/prop/goods?id=" + item.parameter' v-else>
{{ item.name }}({{ GameTool.GetCurrencyNameAll(item.price, item.payType) }})</Abar>
[<Abutton @click="ShopView(item)">购买</Abutton>]
</div>
</div>
<div class="content">
<Pagination :currentPage="currentPage" :limit="10" :total="total" @pageChange="handlePageChange" />
</div>
<!-- 购买 -->
<GamePopup v-model:show="showBuy" title="【购买】">
<!-- 自定义内容 -->
<div class="common">
物品名称{{ showGoods.name }}<br>
购买价格{{ GameTool.GetCurrencyNameAll(showGoods.price, showGoods.payType) }}<br>
</div>
<div class="common" style="text-align: center;">
购买数量<input type="number" class="search-ipt" v-model="count"><br>
<button class="ipt-btn" name="serch" @click="ShopOk" style="margin-top: 15px;">确认</button>
</div>
</GamePopup>
</template>
<script setup lang="ts">
definePageMeta({
layout: layout.default,
middleware: 'page-loading'
})
const currentPage = ref<number>(1);
const total = ref<number>(0);
const data = ref<Array<any>>([]);
const npcName = ref('');
const showBuy = ref(false);
const showGoods = ref<any>({});
const count = ref(1);
onMounted(async () => {
try {
await BindData();
}
finally {
PageLoading.Close();
}
})
const BindData = async (): Promise<void> => {
let npcId = LocalStorageHelper.GetOnNpc();
let result = await StoreService.GetNpcStore(Number(npcId), currentPage.value);
if (result.code == 0) {
data.value = result.data.data;
total.value = result.data.total;
npcName.value = result.data.npcName;
}
else {
MessageExtend.ShowDialog("提示", result.msg);
}
};
/**翻页 */
const handlePageChange = async (page: number): Promise<void> => {
currentPage.value = page;
await BindData();
};
//购买
const ShopView = (info: any) => {
showGoods.value = info;
showBuy.value = true;
count.value = 1;
}
const ShopOk = async (): Promise<void> => {
if (count.value < 1 || count.value > 99) {
MessageExtend.ShowToast("每次购买数量在1~99哦.");
return;
}
MessageExtend.LoadingToast("购买中...");
let npcId = LocalStorageHelper.GetOnNpc();
let result = await StoreService.Buy(Number(npcId), showGoods.value.storeId, count.value);
MessageExtend.LoadingClose();
if (result.code == 0) {
showBuy.value = false;
MessageExtend.Notify(`成功购买${showGoods.value.name}×${count.value}`, "success");
}
else {
MessageExtend.ShowDialog("提示", result.msg);
}
};
</script>

View File

@@ -0,0 +1,141 @@
<template>
<div class="content">
选择出售
<Acheak @click="Change('0')" :on-value="type" on-cheak="0">装备</Acheak>.
<Acheak @click="Change('1')" :on-value="type" on-cheak="1">药品</Acheak>.
<Acheak @click="Change('2')" :on-value="type" on-cheak="2">物品</Acheak>
</div>
<div class="common serch">
搜索内容<input type="text" class="search-ipt" v-model="serch">&nbsp;
<button class="ipt-btn" name="serch" @click="BindData">搜索</button>
</div>
<div class="content">
<div class="common" v-if="type == '0'">
<div class="item" v-for="(item, index) in data" :key="index">
{{ PageExtend.GetPageIndex(currentPage, 10, index + 1) }}.
<Abar :href='"/prop/goods?ue=" + item.ueId'>{{ item.equName }}({{ item.lev }})</Abar>
[<Abutton @click="SaleView(item)">出售</Abutton>]
</div>
</div>
<div class="common" v-if="type == '1'">
<div class="item" v-for="(item, index) in data" :key="index">
{{ PageExtend.GetPageIndex(currentPage, 10, index + 1) }}.
<Abar :href='"/prop/goods?id=" + item.goodsId'>{{ item.goodsName }}({{item.count}})</Abar>
[<Abutton @click="SaleView(item)">出售</Abutton>]
</div>
</div>
<div class="common" v-if="type == '2'">
<div class="item" v-for="(item, index) in data" :key="index">
{{ PageExtend.GetPageIndex(currentPage, 10, index + 1) }}.
<span v-if="item.code == 'Card'">
<Abar :href='"/prop/goods?id=" + item.goodsId'>{{ item.goodsName }}({{item.count}})</Abar>
</span>
<span v-else>
<Abar :href='"/prop/goods?id=" + item.goodsId'>{{ item.goodsName }}({{item.count}})</Abar>
</span>
[<Abutton @click="SaleView(item)">出售</Abutton>]
</div>
</div>
<span v-if="data.length == 0">暂无.</span>
</div>
<div class="content">
<Pagination :currentPage="currentPage" :limit="10" :total="total" @pageChange="handlePageChange" />
</div>
<!-- 购买 -->
<GamePopup v-model:show="showSale" title="【出售】">
<!-- 自定义内容 -->
<div class="common" v-if="type == '0'">
物品名称{{ showGoods.equName }}<br>
出售价格{{ GameTool.FormatCopper(showGoods.sysPrice) }}<br>
</div>
<div class="common" v-else>
物品名称{{ showGoods.goodsName }}<br>
出售价格{{ GameTool.FormatCopper(showGoods.sysPrice) }}<br>
背包数量{{ showGoods.count }}<br>
出售数量<input type="number" class="search-ipt" v-model="count"><br>
</div>
<div class="common" style="text-align: center;">
<button class="ipt-btn" name="serch" @click="SaleOk" style="margin-top: 15px;">确认</button>
</div>
</GamePopup>
</template>
<script setup lang="ts">
definePageMeta({
layout: layout.default,
middleware: 'page-loading'
})
const currentPage = ref<number>(1);
const total = ref<number>(0);
const data = ref<Array<any>>([]);
const serch = ref('');
const type = ref('0');
onMounted(async () => {
try {
await BindData();
}
finally {
PageLoading.Close();
}
})
const BindData = async (): Promise<void> => {
let npcId = LocalStorageHelper.GetOnNpc();
let result = await StoreService.GetNpcSale(Number(npcId), Number(type.value), serch.value, currentPage.value);
if (result.code == 0) {
data.value = result.data.data;
total.value = result.data.total;
}
else {
MessageExtend.ShowDialog("提示", result.msg);
}
};
/**翻页 */
const handlePageChange = async (page: number): Promise<void> => {
currentPage.value = page;
await BindData();
};
const Change = async (_type: string): Promise<void> => {
type.value = _type;
await BindData();
};
//出售
const showSale = ref(false);
const showGoods = ref<any>({});
const count = ref(1);
const SaleView = (info: any) => {
showGoods.value = info;
showSale.value = true;
count.value = 1;
}
const SaleOk = async (): Promise<void> => {
if (type.value != '0' && (count.value < 1 || count.value > showGoods.value.count)) {
MessageExtend.ShowToast("出售数量不正确.");
return;
}
MessageExtend.LoadingToast("出售中...");
let npcId = LocalStorageHelper.GetOnNpc();
let propId = '';
if (type.value == '0') {
propId = showGoods.value.ueId;
}
else {
propId = showGoods.value.ugId;
}
let result = await StoreService.Sale(Number(npcId), count.value, serch.value, Number(type.value), propId);
MessageExtend.LoadingClose();
if (result.code == 0) {
showSale.value = false;
MessageExtend.Notify(result.msg,"success");
await BindData();
}
else {
MessageExtend.ShowDialog("提示", result.msg);
}
};
</script>

View File

@@ -70,7 +70,7 @@ const BindData = async (): Promise<void> => {
userData.value = result.data.user;
attrData.value = result.data.attr;
accData.value = result.data.acc;
online.value = result.data.isOnline;
online.value = result.data.isOnline;
onMap.value = result.data.onMapName;
console.log(result);
}

View File

@@ -30,4 +30,12 @@ export class MapService {
static async GetAutoMapPath(toMap: string) {
return await ApiService.Request("get", "/Map/Map/GetAutoMapPath", { toMap });
}
/**
* 获取NPC相关信息
* GET /Map/Map/GetNpcInfo
*/
static async GetNpcInfo(npcId: number) {
return await ApiService.Request("get", "/Map/Map/GetNpcInfo", { npcId });
}
}

View File

@@ -0,0 +1,41 @@
export class StoreService {
/**
* 获取npc商店信息
* GET /Map/Store/GetNpcStore
*/
static async GetNpcStore(npcId: number, page: number) {
return await ApiService.Request("get", "/Map/Store/GetNpcStore", { npcId, page });
}
/**
* 购买物品
* POST /Map/Store/Buy
* @param npcId body
* @param storeId body
* @param count body
*/
static async Buy(npcId: number, storeId: string, count: number) {
return await ApiService.Request("post", "/Map/Store/Buy", { npcId, storeId, count });
}
/**
* 出售物品
* GET /Map/Store/GetNpcSale
*/
static async GetNpcSale(npcId: number, type: number, query: string, page: number) {
return await ApiService.Request("get", "/Map/Store/GetNpcSale", { npcId, type, query, page });
}
/**
* 出售物品
* POST /Map/Store/Sale
* @param npcId body
* @param count body
* @param search body
* @param type body
* @param id body
*/
static async Sale(npcId: number, count: number, search: string, type: number, id: string) {
return await ApiService.Request("post", "/Map/Store/Sale", { npcId, count, search, type, id });
}
}

View File

@@ -1,9 +1,9 @@
export class GameTool {
/**
* 静态方法:将总铜数转换为 金/银/铜 字符串
* @param totalCopper 总铜数量
* @returns 格式化字符串1金 234银 567铜
*/
/**
* 静态方法:将总铜数转换为 金/银/铜 字符串
* @param totalCopper 总铜数量
* @returns 格式化字符串1金 234银 567铜
*/
public static FormatCopper(totalCopper: number | string): string {
// 安全转为数字并取整(货币无小数)
let copper = Math.floor(Number(totalCopper) || 0);
@@ -35,4 +35,49 @@ export class GameTool {
return result;
}
/**获取货币名称 */
public static GetCurrencyName(pay: string): string {
let result = "";
switch (pay) {
case 'gold':
result = '金元';
break;
case 'cowry':
result = '金贝';
break;
case 'copper':
result = '铜贝';
break;
case 'teach':
result = '师德';
break;
case 'renown':
result = '声望';
break;
}
return result;
}
public static GetCurrencyNameAll(num: number, pay: string): string {
let result = "";
switch (pay) {
case 'gold':
result = '金元';
break;
case 'cowry':
result = '金贝';
break;
case 'copper':
return this.FormatCopper(num);
break;
case 'teach':
result = '师德';
break;
case 'renown':
result = '声望';
break;
}
return `${num}${result}`;
}
}