123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <template>
- <div class="body" style="font-size:14px">
- <el-button type="primary" size="mini" style="float: right; margin-bottom: 20px;" @click="handleAdd">添加特征</el-button>
- <el-table stripe :data="tableData" border style="width: 100%">
- <el-table-column prop="name" label="实例名称" />
- <el-table-column prop="thumb" label="实例图片">
- <template slot-scope="scope">
- <el-image :src="scope.row.thumb" style="width: 100px; height: 100px" />
- </template>
- </el-table-column>
- <el-table-column prop="createDate" label="创建时间">
- <template slot-scope="scope">{{
- scope.row.createDate.substr(0, 10)
- }}</template>
- </el-table-column>
- <el-table-column fixed="right" label="操作">
- <template slot-scope="scope">
- <el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
- <el-popconfirm
- icon="el-icon-info"
- icon-color="red"
- title="确定删除这个特征吗?"
- @onConfirm="handleDelete(scope.row)"
- >
- <el-button slot="reference" type="text">删除</el-button>
- </el-popconfirm>
- </template>
- </el-table-column>
- </el-table>
- <el-pagination
- v-show="characterTotal!==0"
- style="float:right; margin:20px 0"
- :total="characterTotal"
- :current-page="currentPage"
- :page-size="pageSize"
- layout="total, prev, pager, next, sizes"
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- />
- </div>
- </template>
- <script>
- import { getGameCharacterList, deleteGameCharacter } from '@/api/gameCharacter'
-
- export default {
- props: {
- gameId: String
- },
- data() {
- return {
- name: undefined,
- daterange: '',
- tableData: [],
- endDate: undefined,
- startDate: undefined,
- pageSize: 10,
- currentPage: 1,
- characterTotal: 0
- }
- },
- watch: {
- gameId: {
- handler(val) {
- if (this.gameId) {
- this.onSearch()
- }
- },
- immediate: true // 页面加载时就启动
- }
- },
- methods: {
- // 改变每页显示条数
- handleSizeChange(val) {
- this.pageSize = val
- this.changePagination()
- },
- // 改变页码
- handleCurrentChange(val) {
- this.currentPage = val
- this.changePagination()
- },
- // 改变分页组件重新查询数据
- changePagination() {
- getGameCharacterList({
- gameId: this.gameId,
- pageNum: this.currentPage,
- pageSize: this.pageSize
- }).then((res) => {
- this.tableData = res.data.records
- // 讲特征列表写入store 供问题答案特征下拉使用
- const list = []
- this.tableData.map(item => {
- list.push({ characterId: item.characterId, name: item.name })
- })
- this.$store.dispatch('game/setWordListValue', list).then(() => {})
- })
- },
- handleAdd() {
- this.$emit('handleAddGameCharacter', true)
- },
- handleEdit(row) {
- this.$emit('handleEditGameCharacter', row.characterId)
- },
- handleDelete(row) {
- deleteGameCharacter(row.characterId).then(() => {
- // 让父组件给右边编辑特征页面一个空的characterId
- // 防止当前特征正在编辑时删除了右边再次进行保存会报错
- this.$message('删除特征成功')
- this.$emit('handleCloseGameCharacter', true)
- this.onSearch()
- })
- },
- onSearch() {
- getGameCharacterList({
- gameId: this.gameId
- }).then((res) => {
- this.tableData = res.data.records
- this.characterTotal = res.data.total
- this.pageSize = res.data.size
- // 讲特征列表写入store 供问题答案特征下拉使用
- const list = []
- this.tableData.map(item => {
- list.push({ characterId: item.characterId, name: item.name })
- })
- this.$store.dispatch('game/setWordListValue', list).then(() => {})
- })
- },
- dateChange(val) {
- this.startDate = this.daterange[0]
- this.endDate = this.daterange[1]
- }
- }
- }
- </script>
- <style>
- </style>
|