page.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <d2-container>
  3. <el-row style="width: 100%" justify="space-between">
  4. <el-col :span="20">
  5. <el-form :inline="true" :model="formInline" class="demo-form-inline">
  6. <el-form-item label="游戏名">
  7. <el-input v-model="formInline.name" placeholder="游戏名"></el-input>
  8. </el-form-item>
  9. <el-form-item label="AppId">
  10. <el-input v-model="formInline.app_id" placeholder="app_id"></el-input>
  11. </el-form-item>
  12. <!-- <el-form-item label="类型">-->
  13. <!-- <el-select v-model="formInline.game_status" placeholder="类型">-->
  14. <!-- <el-option label="全部" value="0"></el-option>-->
  15. <!-- <el-option label="预约" value="1"></el-option>-->
  16. <!-- <el-option label="内测" value="2"></el-option>-->
  17. <!-- <el-option label="上架" value="3"></el-option>-->
  18. <!-- </el-select>-->
  19. <!-- </el-form-item>-->
  20. <el-form-item>
  21. <el-button type="primary" @click="onSubmit">查询</el-button>
  22. <el-button type="primary" @click="onReset">重置</el-button>
  23. </el-form-item>
  24. </el-form>
  25. </el-col>
  26. <el-col :span="2">
  27. <el-button type="primary" @click="onAdd">添加游戏</el-button>
  28. </el-col>
  29. </el-row>
  30. <el-table :data="tableData" style="width: 100%" v-loading="loading">
  31. <el-table-column label="图标 & 游戏名" width="180">
  32. <template slot-scope="scope">
  33. <el-row :gutter="1" align="middle">
  34. <el-col :span="4">
  35. <el-image :src="scope.row.icon" lazy style="width: 30px; height: 30px" v-show="scope.row.icon"></el-image>
  36. <span class="tag-group__title" v-show="!scope.row.icon"> - </span>
  37. </el-col>
  38. <el-col :span="20" >
  39. <span>{{ scope.row.name }}</span>
  40. </el-col>
  41. </el-row>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="游戏ID" width="180">
  45. <template slot-scope="scope">
  46. <span>{{ scope.row.app_id }}</span>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="添加时间" width="180">
  50. <template slot-scope="scope">
  51. <span>{{ scope.row.created_at }}</span>
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="操作" width="200">
  55. <template slot-scope="scope">
  56. <el-row :gutter="1" align="middle" justify="center">
  57. <el-col :span="10">
  58. <el-link icon="el-icon-download" type="primary" :href="scope.row.url" v-show="scope.row.url">下载</el-link>
  59. <span class="tag-group__title" v-show="!scope.row.url"> - </span>
  60. </el-col>
  61. <el-col :span="10" >
  62. <el-button size="mini" type="success" v-clipboard:copy="scope.row.url" v-clipboard:success="onCopy" v-clipboard:error="onError">复制</el-button>
  63. </el-col>
  64. </el-row>
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. <el-pagination
  69. background
  70. layout="total, sizes, prev, pager, next, jumper"
  71. @size-change="handleSizeChange"
  72. @current-change="handleCurrentChange"
  73. :page-sizes="pagination.page_sizes"
  74. :page-size="pagination.limit"
  75. :current-page="pagination.page"
  76. :total="pagination.total">
  77. </el-pagination>
  78. <el-dialog title="添加游戏" :visible.sync="dialogVisible" width="20%" label-width="100px">
  79. <el-form ref="ruleAddForm" :model="form" label-width="80px" :rules="rules" class="demo-ruleForm">
  80. <el-form-item label="游戏名" prop="name">
  81. <el-input v-model="form.name"></el-input>
  82. </el-form-item>
  83. <el-form-item label="AppId" prop="app_id">
  84. <el-input v-model="form.app_id"></el-input>
  85. </el-form-item>
  86. <el-form-item>
  87. <el-button type="primary" @click="onAddSubmit('ruleAddForm')">提交</el-button>
  88. <el-button @click="resetAddForm('ruleAddForm')">重置</el-button>
  89. </el-form-item>
  90. </el-form>
  91. </el-dialog>
  92. </d2-container>
  93. </template>
  94. <script>
  95. import api from '@/api'
  96. export default {
  97. name: 'game',
  98. data () {
  99. return {
  100. dialogVisible: false,
  101. form: {
  102. name: '',
  103. app_id: ''
  104. },
  105. rules: {
  106. name: [
  107. { required: true, message: '请输入游戏名', trigger: 'blur' }
  108. ],
  109. app_id: [
  110. { required: true, message: '请输入 app_id', trigger: 'blur' }
  111. ]
  112. },
  113. formInline: {
  114. name: '',
  115. app_id: '',
  116. game_status: 3
  117. },
  118. tableData: [],
  119. loading: false,
  120. pagination: {
  121. page: 1, // 页数
  122. limit: 15, // 页数数量
  123. total: 0, // 总数
  124. page_sizes: [20, 50, 100, 500, 1000] // 页数数量
  125. }
  126. }
  127. },
  128. mounted () {
  129. this.fetchData()
  130. },
  131. methods: {
  132. // 提交
  133. onSubmit (res) {
  134. this.fetchData(this.formInline)
  135. },
  136. // 重置
  137. onReset () {
  138. this.fetchData()
  139. },
  140. onAdd () {
  141. this.dialogVisible = true
  142. },
  143. onAddSubmit (formName) {
  144. this.$refs[formName].validate((valid) => {
  145. if (valid) {
  146. api.GAME_ADD(this.form).then(res => {
  147. this.$message({
  148. showClose: true,
  149. message: '添加成功!',
  150. type: 'success'
  151. })
  152. this.fetchData()
  153. this.dialogVisible = false
  154. }).catch(err => {
  155. console.log(err)
  156. this.$message({
  157. showClose: true,
  158. message: '添加失败!',
  159. type: 'error'
  160. })
  161. })
  162. }
  163. })
  164. },
  165. resetAddForm (formName) {
  166. this.$refs[formName].resetFields()
  167. },
  168. // 列表
  169. async fetchData (where = {}) {
  170. this.loading = true
  171. api.GAME_LIST(where).then(res => {
  172. this.tableData = res.data
  173. this.pagination.page = res.current_page
  174. this.pagination.limit = res.per_page
  175. this.pagination.total = res.total
  176. this.loading = false
  177. console.log('# GAME_LIST: ', res)
  178. }).catch(err => {
  179. console.log('err', err)
  180. this.loading = false
  181. })
  182. },
  183. // table -- 操作按钮
  184. handleEdit (index, row) {
  185. console.log(index, row)
  186. },
  187. handleDelete (index, row) {
  188. console.log(index, row)
  189. },
  190. onCopy () {
  191. this.$message({
  192. showClose: true,
  193. message: '复制成功!',
  194. type: 'success'
  195. })
  196. },
  197. onError () {
  198. this.$message({
  199. showClose: true,
  200. message: '复制失败!',
  201. type: 'error'
  202. })
  203. },
  204. // 分页
  205. handleSizeChange (val) {
  206. // this.pagination.limit = val
  207. this.fetchData({ limit: val })
  208. console.log(`每页 ${val} 条`)
  209. },
  210. handleCurrentChange (val) {
  211. this.pagination.page = val
  212. this.fetchData({ page: val })
  213. console.log(`当前页: ${val}`)
  214. }
  215. }
  216. }
  217. </script>