1
0
Fork 0
forked from Simnation/Main
Main/resources/[tools]/unlimited-spectre/html/assets/Item.d7c8acff.js

2 lines
15 KiB
JavaScript
Raw Normal View History

2025-06-07 08:51:21 +02:00
import{_ as D,R as E,P as F,o as g,X as y,a7 as a,a as i,w as s,a6 as v,ab as b,c as k,V as _,a5 as u,W as f,U as d,a9 as p,aP as x,aQ as I,aT as V,Y as M,Z as R,bF as L,S as j,a8 as T}from"./app-014d9ed9.js";import{Q as O}from"./QTooltip.9d840032.js";import{Q as S}from"./QImg.91aecb73.js";import{a as N,Q as w,c as Q}from"./QItemLabel.b6dd3adb.js";import{Q as h}from"./QSelect.d7ce3d4c.js";import{Q as A}from"./QBadge.718e7c58.js";import{Q as B}from"./QMarkupTable.ba6854cc.js";import{Q as z}from"./QForm.8d79ab03.js";import{B as $}from"./BasicDialog.9dd9de92.js";import{d as P}from"./utils.9ce591f3.js";import{e as H}from"./externalHosting.js";import"./position-engine.65ebcb34.js";import"./selection.2a17b691.js";import"./rtl.b51694b1.js";const q={anim:{lib:"",dict:"",text:"",timeOut:null},accept:[],reward:""},J={name:"Item",data(){return{externalHosting:H,RESOURCE:E,ACTION:F,defaults:["shouldclose","type","description","weight","label","unique","useable","image","name","combinable"],pendingSave:!1,pendingDelete:!1,item:{},customVars:[],itemTypes:["item","weapon"],items:[],itemImages:[],itemsReward:[],itemsAccept:[""],imageAccept:[""],combinable:q}},computed:{getRewardLabel(){const e=this.items.find(t=>t.value===this.combinable.reward);return e?e.label:this.combinable.reward}},methods:{can:P,isNumeric(e){return typeof e!="string"?!1:!isNaN(e)&&!isNaN(parseFloat(e))},isBoolean(e){return e==="true"||(e==="false"?!1:e)},addCustomVar(){this.customVars.push({name:"",value:""})},removeVar(e,t){e>-1&&this.$q.dialog({component:$,componentProps:{title:this.$i18n.t("components.item.deleteHeader"),message:this.$i18n.t("components.item.deleteCustomVarMsg",{name:t.name})},cancel:!0,persistent:!0}).onOk(()=>{delete this.item[t.oldName],this.customVars.splice(e,1)})},triggerFileSelect(){this.$refs.image.value=null,this.$refs.image.click()},uploadImage(e){if(!this.$refs.image.value)return;const t=e.target.files[0];let m=new FormData;m.set("file",t),m.set("name",t.name),this.$axios.post("/api/items/icon-upload",m).then(r=>{if(!r.data.resCode){const n=r.data.resMsg;this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t(`components.item.msg.error.${n}`)});return}this.$q.notify({message:this.$i18n.t("general.success"),position:"top",color:"green",icon:"fas fa-check",caption:this.$i18n.t("components.item.uploadedImage")}),this.itemImages=Object.freeze(r.data.images),this.item.image=r.data.filename})},trySave(){this.$refs.customVarForm.validate().then(e=>{if(!e){this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t("components.item.msg.error.uniqueVars")});return}this.customVars.forEach(t=>{!t.name||(t.oldName=t.name,this.item[t.name]=this.isNumeric(t.value)?Number(t.value):this.isBoolean(t.value))}),this.pendingSave=!0,Object.entries(this.combinable).sort().toString()!==Object.entries(q).sort().toString()&&(this.item.combinable=this.combinable),this.$axios.patch(`/api/items/save/${this.item.name}`,this.item).then(t=>{if(this.pendingSave=!1,!t.data.resCode){const r=t.data.resMsg;this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t(`components.item.msg.error.${r}`,{name:this.item.name})});return}this.$q.notify({message:this.$i18n.t("general.success"),position:"top",color:"green",icon:"fas fa-check",caption:this.$i18n.t("general.saved")})}).catch(t=>{})})},tryDelete(){this.pendingDelete=!0,this.$q.dialog({component:$,componentProps:{title:this.$i18n.t("components.item.deleteHeader"),message:this.$i18n.t("components.item.deleteMsg",{itemLabel:this.item.label,itemName:this.item.name})},cancel:!0,persistent:!0}).onOk(()=>{this.$axios.delete(`/api/items/delete/${this.item.name}`).then(e=>{if(this.pendingDelete=!1,!e.data.resCode){const m=e.data.resMsg;this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t(`components.item.msg.er