Commit 12538fbd authored by nanahira's avatar nanahira

use deckform for deckprint

parent 7d23fb2b
Pipeline #41218 passed with stages
in 1 minute and 31 seconds
......@@ -20,18 +20,23 @@
<el-input v-model="form.event" placeholder="请输入Event" auto-complete="off" width="10px"></el-input>
</el-form-item>
<!-- 改成 lastInitial -->
<el-form-item label="参赛ID" :label-width="formLabelWidth">
<el-input v-model="form.gameid" placeholder="请输入gameid" auto-complete="off" width="10px"></el-input>
<el-input v-model="form.lastInitial" placeholder="请输入 lastInitial" auto-complete="off" width="10px"></el-input>
</el-form-item>
<el-form-item label="日期" :label-width="formLabelWidth">
<el-date-picker v-model="form.date" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd">
<el-date-picker
v-model="form.date"
type="date"
placeholder="选择日期"
format="yyyy 年 MM 月 dd 日"
value-format="yyyy-MM-dd">
</el-date-picker>
<!--<el-input v-model="form.date" placeholder="请输入" auto-complete="off" width="10px"></el-input>-->
</el-form-item>
<el-form-item label="模版选择" :label-width="formLabelWidth">
<!-- 模板选择:仅隐藏 UI,保留控件(v-show=false) -->
<el-form-item label="模版选择" :label-width="formLabelWidth" v-show="false">
<el-select v-model="value" placeholder="请选择">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
</el-option>
......@@ -39,15 +44,18 @@
</el-form-item>
<el-form-item label="ydk文件" :label-width="formLabelWidth">
<el-upload class="upload-demo" :action="uploadUrl" :on-change="handleChange" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload"
<!-- 只选择文件,不走旧的自动上传。保留 before/after 钩子最小侵入 -->
<el-upload
class="upload-demo"
:on-change="handleChange"
:auto-upload="false"
:file-list="fileList3">
<el-button size="small" type="primary">点击上传</el-button>
<el-button size="small" type="primary">选择文件</el-button>
<div slot="tip" class="el-upload__tip">上传卡组文件,大小不能超过3KB</div>
</el-upload>
</el-upload>
</el-form-item>
<el-form-item label="备选项" :label-width="formLabelWidth">
<!--<el-checkbox v-model="checked">是否生成图片</el-checkbox>-->
<el-checkbox v-model="checked2">是否打印(会帮您调用打印程序)</el-checkbox>
</el-form-item>
......@@ -62,173 +70,181 @@
</template>
<script>
import querystring from 'querystring';
import crypto from 'crypto';
import API from '../api'
import { mapGetters } from 'vuex'
import moment from 'moment'
import tb_language from './tb_lang.js'
import Footads from './Footads'
export default {
components: {
Footads
},
data() {
return {
fileList3: [],
options: [{
value: '1',
label: '默认'
}, {
value: '2',
label: 'KONAMI'
}],
value: '1',
isIE: false,
form: {
name: '',
event: '',
date: '',
gameid: '',
},
formLabelWidth: '80px',
isNew: true,
isClick: false,
todayCount: 0,
uploadUrl: API.uploadUrl,
imageUrl: "",
downloadPath: "",
demo_title: "",
demo_url: "",
demo1: [],
// checked: false,
checked2: false,
demo2: []
}
},
created: function () {
setTimeout(function () {
$(".el-upload__input").hide()
}, 100)
this.isIE = this.isIEMethod();
// 移除失效 API 的使用(最小改动:删除 import API 并清空相关字段的用途)
import querystring from 'querystring';
import crypto from 'crypto';
import { mapGetters } from 'vuex'
import moment from 'moment'
import tb_language from './tb_lang.js'
import Footads from './Footads'
export default {
components: { Footads },
data() {
return {
fileList3: [],
options: [
{ value: '1', label: '默认' },
{ value: '2', label: 'KONAMI' }
],
value: '1',
isIE: false,
form: {
name: '',
event: '',
date: '',
// gameid -> lastInitial
lastInitial: '',
},
formLabelWidth: '80px',
isNew: true,
isClick: false,
todayCount: 0,
// 旧的 uploadUrl / imageUrl / downloadPath 废弃
imageUrl: "",
downloadPath: "",
demo_title: "",
demo_url: "",
demo1: [],
checked2: false,
demo2: []
}
},
created: function () {
setTimeout(function () {
$(".el-upload__input").hide()
}, 100)
this.isIE = this.isIEMethod();
},
computed: {
...mapGetters({
lang: 'getLang',
user: 'getUser'
}),
},
methods: {
handleChange(file, fileList) {
this.fileList3 = fileList.slice(-1);
},
computed: {
...mapGetters({
lang: 'getLang',
user: 'getUser'
}),
// 保留但不再使用旧上传回调
handleAvatarSuccess(res, file) {
// 不再使用旧下载路径
},
methods: {
handleChange(file, fileList) {
this.fileList3 = fileList.slice(-1);
},
handleAvatarSuccess(res, file) {
this.downloadPath = file.response.path
this.imageUrl = URL.createObjectURL(file.raw);
},
beforeAvatarUpload(file) {
var type = /\.[^\.]+/.exec(file.name);
const isJPG = type[0] === '.ydk';
const isLt2M = file.size / 1024 < 3;
if (!isJPG) {
this.$message.error('上传文件只能是 ydk 格式!');
return false
}
if (!isLt2M) {
this.$message.error('上传文件大小不能超过 3KB!');
return false
}
return true;
},
// 选择文件阶段可选校验:保持原逻辑最小复用(现在不自动上传,所以在提交时再严格校验)
beforeAvatarUpload(file) {
var type = /\.[^\.]+/.exec(file.name);
const isYDK = type && type[0] === '.ydk';
const isLt3KB = file.size / 1024 < 3;
download: function () {
window.location.href = API.getDownloadUrl(this.downloadPath)
},
if (!isYDK) {
this.$message.error('上传文件只能是 ydk 格式!');
return false
}
if (!isLt3KB) {
this.$message.error('上传文件大小不能超过 3KB!');
return false
}
return true;
},
isIEMethod: function (ver) {
var b = document.createElement('b')
b.innerHTML = '<!--[if IE ' + ver + ']><i></i><![endif]-->'
return b.getElementsByTagName('i').length === 1
},
// 旧下载方法废弃
download: function () {},
onSubmit: function () {
// if (!this.form.name || !this.form.name.trim()) {
// this.$notify({
// title: '警告',
// message: '请输入姓名!',
// type: 'error'
// })
// return;
// }
// if (!this.form.event || !this.form.event.trim()) {
// this.$notify({
// title: '警告',
// message: '请输入event!',
// type: 'error'
// })
// return;
// }
var date;
if (this.form.date) {
date = moment(this.form.date).format('YYMMDD')
}
isIEMethod: function (ver) {
var b = document.createElement('b')
b.innerHTML = '<!--[if IE ' + ver + ']><i></i><![endif]-->'
return b.getElementsByTagName('i').length === 1
},
if (!this.downloadPath || !this.downloadPath.trim()) {
this.$notify({
title: '警告',
message: '请上传ydk文件!',
type: 'error'
})
// 改为直传 /api/fill
async onSubmit() {
// 取出表单字段
const { name, event, date, lastInitial } = this.form;
// 文件检查
if (!this.fileList3.length || !this.fileList3[0].raw) {
this.$notify({
title: '警告',
message: '请先选择 ydk 文件!',
type: 'error'
});
return;
}
const file = this.fileList3[0].raw;
// 轻量校验(沿用原限制)
const ok = this.beforeAvatarUpload(file);
if (!ok) return;
// === 全局 Loading 遮罩 ===
const loading = this.$loading({
lock: true,
text: '正在生成...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
});
try {
const qs = new URLSearchParams({
name: name || '',
event: event || '',
date: date || '',
lastInitial: lastInitial || ''
}).toString();
const formData = new FormData();
formData.append('file', file); // multipart/form-data
const resp = await fetch(`https://deckform.yuzurisa.com:444/api/fill?${qs}`, {
method: 'POST',
body: formData
});
if (!resp.ok) {
let errText = '生成失败';
try {
const ct = resp.headers.get('content-type') || '';
if (ct.includes('application/json')) {
const j = await resp.json();
errText = (j && j.message) || errText;
} else {
errText = await resp.text();
}
} catch (e) {}
this.$notify({ title: '错误', message: errText, type: 'error' });
return;
}
var opt = {
name: this.form.name,
event: this.form.event,
gameid: this.form.gameid,
date: date,
id: this.downloadPath.slice(7),
// img: this.checked,
print: this.checked2,
}
// var baseUrl = "http://localhost:8081"
var baseUrl = "https://mycard.world/ygopro/arena"
const blob = await resp.blob();
const url = URL.createObjectURL(blob);
const win = window.open(url, "_blank");
var template = "deck"
if (this.value === "1") {
template = "deck"
if (this.checked2 && win) {
setTimeout(() => {
try { win.focus(); win.print(); } catch (e) {}
}, 800);
}
if (this.value === "2") {
template = "konami"
}
var request = querystring.stringify(opt);
var url = `${baseUrl}/${template}.html?${request}`;
window.open(url, "_blank");
},
} catch (e) {
this.$notify({
title: '错误',
message: '网络异常或服务器错误',
type: 'error'
});
} finally {
loading.close();
}
},
}
},
}
</script>
<style scoped>
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment