This commit is contained in:
yangduo 2025-01-26 11:56:41 +08:00
parent 97e9cae2ff
commit 15c009026e
4 changed files with 656 additions and 0 deletions

39
src/api/giftcode.js Normal file
View File

@ -0,0 +1,39 @@
import request from '@/utils/request'
export function genCodes(gameid, type, count) {
return request({
url: '/giftcode/gen?gameid=' + gameid + '&type=' + type + '&count=' + count,
method: 'get'
})
}
export function getCodes(data) {
return request({
url: '/giftcode/list',
method: 'post',
data
})
}
export function downloadFile(gameid, batchid) {
return request({
url: '/giftcode/download?gameid=' + gameid + '&batchid=' + batchid,
method: 'get'
})
}
export function addType(data) {
return request({
url: '/giftcode/addtype',
method: 'post',
data
})
}
export function getTypes(data) {
return request({
url: '/giftcode/typelist',
method: 'post',
data
})
}

View File

@ -383,6 +383,18 @@ export const asyncRoutes = [
component: () => import('@/views/activecode/info'), component: () => import('@/views/activecode/info'),
name: 'activecode', name: 'activecode',
meta: { title: '激活码', pername: 'activecode' } meta: { title: '激活码', pername: 'activecode' }
},
{
path: 'giftcode',
component: () => import('@/views/giftcode/info'),
name: 'giftcode',
meta: { title: '生成兑换码', pername: 'giftcode' }
},
{
path: 'giftcodeconfig',
component: () => import('@/views/giftcode/config'),
name: 'giftcodeconfig',
meta: { title: '配置兑换码', pername: 'giftcodeconfig' }
} }
] ]
}, { }, {

View File

@ -0,0 +1,281 @@
<template>
<div class="createPost-container">
<el-form ref="postForm" :model="postForm" :rules="rules" class="form-container">
<div class="createPost-main-container">
<el-row>
<el-col :span="1">
<el-button class="filter-item" style="margin-left: 10px;" type="primary" @click="handleCreate">
新增
</el-button>
</el-col>
<el-col :span="5">
<el-form-item label-width="120px" label="游戏" class="postInfo-container-item" prop="gameid">
<el-select v-model="postForm.gameid">
<el-option label="2004" value="2004" />
<el-option label="2006" value="2006" />
</el-select>
</el-form-item>
</el-col>
<el-button style="margin-left: 10px;" type="success" @click="submitForm()">
查询
</el-button>
<!-- <el-button :key="1" :style="{ display: disabledownload===true ? 'none': '' }" type="success">下载</el-button> -->
</el-row>
<el-table
:empty-text="emptytext"
height="400"
:data="typelist"
border
fit
highlight-current-row
style="width: 100%;"
>
<el-table-column
prop="gameid"
label="gameid"
width="100"
/>
<el-table-column
prop="gift_type"
label="类型id"
width="100"
/>
<el-table-column
prop="content"
label="列表"
/>
</el-table>
<el-pagination
background
:current-page="curpage"
:page-size="page_size"
:page-count="totalpage"
layout="prev, pager, next"
@current-change="handleCurrentChange"
/>
</div>
</el-form>
<el-dialog title="新增" :visible.sync="dialogFormVisible" :close-on-click-modal="false" style="width:80%" @close="handleDialogClose()">
<el-form ref="form" :rules="createrules" :model="form" label-position="left" style="width: 400px; margin-left:50px;">
<el-form-item label-width="70px" label="游戏" class="postInfo-container-item" prop="gameid">
<el-select v-model="form.gameid" style="width: 100px">
<el-option label="2004" value="2004" />
<el-option label="2006" value="2006" />
</el-select>
</el-form-item>
<el-form-item label-width="70px" label="限制" prop="limit" required>
<el-radio-group v-model="form.limit">
<el-radio :label="0">单码多次</el-radio>
<el-radio :label="1">单码单次</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label-width="70px" label="列表:" class="postInfo-container-item" prop="content">
<el-input v-model="form.content" style="width: 100%" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = handleDialogClose()">
Cancel
</el-button>
<el-button type="primary" @click="addGameType()">
Confirm
</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { addType, getTypes } from '@/api/giftcode'
export default {
name: 'GiftCodeConfig',
data() {
// var r = /^\+?[1-9][0-9]*$/
// var validatequery = (rule, value, callback) => {
// if (!this.dialogFormVisible && (!this.postForm.batch_id || !r.test(this.postForm.batch_id))) {
// callback(new Error(''))
// } else {
// callback()
// }
// }
var contentvalidatequery = (rule, value, callback) => {
if (this.dialogFormVisible && !value) {
callback(new Error('请填写itemid:itemnum|itemid:itemnum'))
} else {
callback()
}
}
return {
postForm: {
gameid: ''
},
form: {
gameid: '',
limit: 0,
content: ''
},
rules: {
gameid: [{ required: true, validator: (rule, value, callback) => {
if (!this.dialogFormVisible && !value) {
callback(new Error('请选择'))
} else {
callback()
}
}, trigger: 'blur' }]
},
createrules: {
gameid: [{ required: true, validator: (rule, value, callback) => {
if (this.dialogFormVisible && !value) {
callback(new Error('请选择1'))
} else {
callback()
}
}, trigger: 'blur' }],
content: [{ required: true, validator: contentvalidatequery, trigger: 'blur' }]
},
disabledownload: true,
emptytext: ' ',
typelist: [],
totalpage: 0,
curpage: 1,
page_size: 8,
dialogFormVisible: false,
itemlist: [{
name: 'sss',
type: 1,
price: '$123'
}]
}
},
watch: {
},
mounted() {
},
methods: {
handleDialogClose() {
// this.getList()
},
submitForm() {
try {
this.$refs['postForm'].validate((valid) => {
if (valid) {
this.curpage = 1
this.totalpage = 0
this.getList(true)
}
})
} catch (e) {
console.log(e)
}
},
handleCreate() {
this.form.count = ''
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['form'].clearValidate()
})
},
resetTemp() {
this.postForm = {
gameid: ''
}
},
handleCurrentChange(val) {
this.curpage = val
this.getList(false)
},
getList(query) {
const data = {
'gameid': Number(this.postForm.gameid),
'page_dto': {
'page': this.curpage,
'pageSize': this.page_size
}
}
getTypes(data).then(response => {
this.typelist = response.data
this.totalpage = response.total_page
this.curpage = response.cur_page
if (this.typelist === undefined || this.typelist.length <= 0) {
this.emptytext = 'No data'
}
if (query) {
this.$message({
message: '收到回应',
type: 'success',
duration: 1200
})
}
})
},
addGameType() {
this.$refs['form'].validate((valid) => {
if (valid) {
const data = {
'gameid': Number(this.form.gameid),
'limit': this.form.limit,
'content': this.form.content
}
addType(data).then(response => {
if (response.code === 0) {
this.dialogFormVisible = false
this.curpage = 1
this.postForm.gameid = this.form.gameid
this.getList(true)
this.$notify({
title: 'Success',
message: 'Created Successfully',
type: 'success',
duration: 2000
})
}
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
@import "~@/styles/mixin.scss";
.createPost-container {
position: relative;
.createPost-main-container {
padding: 40px 45px 20px 50px;
.postInfo-container {
position: relative;
@include clearfix;
margin-bottom: 10px;
.postInfo-container-item {
float: left;
}
}
}
.word-counter {
width: 40px;
position: absolute;
right: 10px;
top: 0px;
}
}
.article-textarea ::v-deep {
textarea {
padding-right: 40px;
resize: none;
border: none;
border-radius: 0px;
border-bottom: 1px solid #bfcbd9;
}
}
</style>

324
src/views/giftcode/info.vue Normal file
View File

@ -0,0 +1,324 @@
<template>
<div class="createPost-container">
<el-form ref="postForm" :model="postForm" :rules="rules" class="form-container">
<div class="createPost-main-container">
<el-row>
<el-col :span="1">
<el-button class="filter-item" style="margin-left: 10px;" type="primary" @click="handleCreate">
新增
</el-button>
</el-col>
<el-col :span="5">
<el-form-item label-width="120px" label="游戏" class="postInfo-container-item" prop="gameid">
<el-select v-model="postForm.gameid">
<el-option label="2004" value="2004" />
<el-option label="2006" value="2006" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="5">
<el-form-item label-width="120px" label="批次号:" class="postInfo-container-item" prop="batch_id" required>
<el-input v-model.number="postForm.batch_id" />
</el-form-item>
</el-col>
<el-button style="margin-left: 10px;" type="success" @click="submitForm()">
查询
</el-button>
<el-button :key="1" :style="{ display: disabledownload===true ? 'none': '' }" type="success" @click="download">下载</el-button>
</el-row>
<el-table
:empty-text="emptytext"
height="400"
:data="giftcodelist"
border
fit
highlight-current-row
style="width: 100%;"
>
<el-table-column
prop="gameid"
label="gameid"
width="150"
/>
<el-table-column
prop="batch_id"
label="批次号"
width="150"
/>
<el-table-column
prop="gift_code"
label="兑换码"
width="150"
/>
<el-table-column
prop="limit"
label="0:不限;1:仅用一次"
width="150"
/>
<el-table-column
prop="count"
label="使用次数"
width="150"
/>
<el-table-column
prop="content"
label="列表"
/>
</el-table>
<el-pagination
background
:current-page="curpage"
:page-size="page_size"
:page-count="totalpage"
layout="prev, pager, next"
@current-change="handleCurrentChange"
/>
</div>
</el-form>
<el-dialog title="新增" :visible.sync="dialogFormVisible" :close-on-click-modal="false" style="width:50%" @close="handleDialogClose()">
<el-form ref="form" :rules="countrules" :model="form" label-position="left" style="width: 400px; margin-left:50px;">
<el-form-item label-width="70px" label="游戏" class="postInfo-container-item" prop="gameid">
<el-select v-model="form.gameid" style="width: 100px">
<el-option label="2004" value="2004" />
<el-option label="2006" value="2006" />
</el-select>
</el-form-item>
<el-form-item label-width="70px" label="类型id:" class="postInfo-container-item" prop="type" required>
<el-input v-model.number="form.type" style="width: 100px" />
</el-form-item>
<el-form-item label-width="70px" label="数量:" class="postInfo-container-item" prop="count" required>
<el-input v-model.number="form.count" style="width: 100px" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = handleDialogClose()">
Cancel
</el-button>
<el-button type="primary" @click="createCodes()">
Confirm
</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { genCodes, getCodes, downloadFile } from '@/api/giftcode'
export default {
name: 'GiftCode',
data() {
var r = /^\+?[1-9][0-9]*$/
var validatequery = (rule, value, callback) => {
if (!this.dialogFormVisible && (!value || !r.test(value))) {
callback(new Error('请填写数字'))
} else {
callback()
}
}
var countvalidatequery = (rule, value, callback) => {
if (this.dialogFormVisible && (!value || !r.test(value))) {
callback(new Error('请填写数字'))
} else {
callback()
}
}
return {
postForm: {
gameid: '',
batch_id: ''
},
form: {
gameid: '',
type: '',
count: ''
},
rules: {
gameid: [{ required: false, validator: (rule, value, callback) => {
if (!this.dialogFormVisible && !value) {
callback(new Error('请选择'))
} else {
callback()
}
}, trigger: 'blur' }],
batch_id: [{ required: false, validator: validatequery, trigger: 'blur' }]
},
countrules: {
gameid: [{ required: false, validator: (rule, value, callback) => {
if (!this.dialogFormVisible && !value) {
callback(new Error('请选择1'))
} else {
callback()
}
}, trigger: 'blur' }],
type: [{ required: false, validator: countvalidatequery, trigger: 'blur' }],
count: [{ required: false, validator: countvalidatequery, trigger: 'blur' }]
},
downloadbatchid: '',
disabledownload: true,
emptytext: ' ',
giftcodelist: [],
totalpage: 0,
curpage: 1,
page_size: 8,
dialogFormVisible: false,
itemlist: [{
name: 'sss',
type: 1,
price: '$123'
}]
}
},
watch: {
},
mounted() {
},
methods: {
handleDialogClose() {
// this.getList()
},
submitForm() {
try {
this.$refs['postForm'].validate((valid) => {
if (valid) {
this.curpage = 1
this.totalpage = 0
this.getList(true)
}
})
} catch (e) {
console.log(e)
}
},
handleCreate() {
this.form.count = ''
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['form'].clearValidate()
})
},
resetTemp() {
this.postForm = {
gameid: '',
batch_id: ''
}
},
handleCurrentChange(val) {
this.curpage = val
this.getList(false)
},
getList(query) {
const data = {
'gameid': Number(this.postForm.gameid),
'batch_id': this.postForm.batch_id,
'page_dto': {
'page': this.curpage,
'pageSize': this.page_size
}
}
getCodes(data).then(response => {
this.giftcodelist = response.data
this.totalpage = response.total_page
this.curpage = response.cur_page
if (this.giftcodelist === undefined || this.giftcodelist.length <= 0) {
this.emptytext = 'No data'
} else if (query) {
this.downloadbatchid = this.postForm.batch_id
this.disabledownload = false
}
if (query) {
this.$message({
message: '收到回应',
type: 'success',
duration: 1200
})
}
})
},
createCodes() {
this.$refs['form'].validate((valid) => {
if (valid) {
genCodes(this.form.gameid, this.form.type, this.form.count).then(response => {
if (response.code === 0) {
this.dialogFormVisible = false
this.postForm.batch_id = response.batchid
this.postForm.gameid = this.form.gameid
this.downloadbatchid = response.batchid
this.disabledownload = true
this.curpage = 1
this.getList(true)
this.$notify({
title: 'Success',
message: 'Created Successfully',
type: 'success',
duration: 2000
})
}
})
}
})
},
download() {
downloadFile(this.postForm.gameid, this.downloadbatchid).then(response => {
if (response.code === 0) {
var csv = 'gameid,batchid,code\r\n'
for (const i in response.data) {
csv += response.data[i]['gameid'] + ',' + response.data[i]['batch_id'] + ',' + response.data[i]['gift_code'] + '\r\n'
}
const content = new Blob(['\uFEFF' + csv])
const urlobj = window.URL || window.webkitURL || window
const url = urlobj.createObjectURL(content)
const el = document.createElement('a')
el.href = url
el.download = this.postForm.gameid + '_' + this.downloadbatchid + '.csv'
el.click()
urlobj.revokeObjectURL(url)
this.disabledownload = true
}
})
}
}
}
</script>
<style lang="scss" scoped>
@import "~@/styles/mixin.scss";
.createPost-container {
position: relative;
.createPost-main-container {
padding: 40px 45px 20px 50px;
.postInfo-container {
position: relative;
@include clearfix;
margin-bottom: 10px;
.postInfo-container-item {
float: left;
}
}
}
.word-counter {
width: 40px;
position: absolute;
right: 10px;
top: 0px;
}
}
.article-textarea ::v-deep {
textarea {
padding-right: 40px;
resize: none;
border: none;
border-radius: 0px;
border-bottom: 1px solid #bfcbd9;
}
}
</style>