dev_show.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <div id="cloud-balance">
  3. <el-button @click="clickAdd">添加</el-button>
  4. <div class="table">
  5. <el-table
  6. v-if="tableData.length"
  7. height="100%"
  8. border
  9. style="width: 100%"
  10. :data="tableData"
  11. :row-class-name="tableRowClassName"
  12. >
  13. <el-table-column
  14. v-for="(prop, index) of tableProps"
  15. :key="index"
  16. :prop="prop"
  17. align="center"
  18. :label="tableHeaders[index]"
  19. >
  20. <template slot-scope="scope">
  21. <el-button
  22. type="text"
  23. v-if="prop === 'uid'"
  24. @click="clickUID(scope.row)"
  25. >{{scope.row[prop]}}</el-button>
  26. <img
  27. v-else-if="prop === 'url'"
  28. :src="scope.row[prop]"
  29. alt="url"
  30. style="display: block; width: 100px; height: 80px;"
  31. >
  32. <section class="ctrls" v-else-if="prop === 'ctrls'">
  33. <el-button type="text" @click="clickEdit(scope.$index, scope.row)">编辑</el-button>
  34. <el-button type="text" @click="clickDel(scope.$index, scope.row)">删除</el-button>
  35. </section>
  36. <span v-else>{{scope.row[prop]}}</span>
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. </div>
  41. <el-dialog title="添加展示" :visible.sync="centerDialogVisible" width="50%" center>
  42. <el-form
  43. :model="ruleForm"
  44. :rules="rules"
  45. ref="ruleForm"
  46. label-width="100px"
  47. class="demo-ruleForm"
  48. >
  49. <el-form-item label="UID" prop="uid">
  50. <el-input type="number" v-model="ruleForm.uid" :disabled="isEdit"></el-input>
  51. </el-form-item>
  52. <el-form-item label="排序" prop="order">
  53. <el-input type="number" v-model="ruleForm.order"></el-input>
  54. </el-form-item>
  55. <el-form-item label="配图" prop="url">
  56. <el-upload
  57. class="avatar-uploader"
  58. action="/api/admin/developer/uploadImg"
  59. :show-file-list="false"
  60. :on-success="handleAvatarSuccess"
  61. :before-upload="beforeAvatarUpload"
  62. >
  63. <img v-if="ruleForm.url" :src="ruleForm.url" class="avatar">
  64. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  65. </el-upload>
  66. </el-form-item>
  67. </el-form>
  68. <span slot="footer" class="dialog-footer">
  69. <el-button @click="centerDialogVisible = false">取 消</el-button>
  70. <el-button type="primary" @click="clickSubmit">确 定</el-button>
  71. </span>
  72. </el-dialog>
  73. </div>
  74. </template>
  75. <script>
  76. const tableHeaders = [
  77. 'ID',
  78. '昵称',
  79. '排序',
  80. '配图',
  81. '添加时间',
  82. '操作',
  83. ]
  84. const tableProps = [
  85. 'uid',
  86. 'nickname',
  87. 'order',
  88. 'url',
  89. 'create_date',
  90. 'ctrls',
  91. ]
  92. export default {
  93. data() {
  94. return {
  95. // 是否是编辑入口
  96. isEdit: false,
  97. ruleForm: {},
  98. rules: {
  99. id: [
  100. { required: true, message: '请填写开发者ID', trigger: 'blur' },
  101. ],
  102. url: [
  103. { type: 'string', required: true, message: '请上传配图', trigger: 'change' }
  104. ],
  105. },
  106. // 弹框
  107. centerDialogVisible: false,
  108. // 数据总条目
  109. totalCount: 0,
  110. currentPage: 1,
  111. // 列表头显示内容
  112. tableHeaders,
  113. // 列表头字段
  114. tableProps,
  115. // 列表数据
  116. tableData: []
  117. }
  118. },
  119. mounted() {
  120. this.getTableData()
  121. },
  122. methods: {
  123. // 点击新增或编辑框的确认
  124. async clickSubmit() {
  125. let url = '/api/admin/developer/addRecommendDeveloper';
  126. if(this.isEdit) url = '/api/admin/developer/editRecommendDeveloper';
  127. const res = await this.$post(url, this.ruleForm);
  128. const data = res.data;
  129. this.getTableData();
  130. this.centerDialogVisible = false;
  131. },
  132. // 点击添加
  133. clickAdd() {
  134. this.ruleForm = {};
  135. this.isEdit = false;
  136. this.centerDialogVisible = true;
  137. },
  138. handleAvatarSuccess(res, file) {
  139. // this.ruleForm.url = res.data.file_url_abs;
  140. this.$set(this.ruleForm, 'url', res.data.file_url_abs);
  141. },
  142. beforeAvatarUpload(file) {
  143. const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
  144. const isLt2M = file.size / 1024 / 1024 < 2;
  145. if(!isJPG) {
  146. this.$message.error('上传头像图片只能是 JPG 或 PNG 格式!');
  147. }
  148. if(!isLt2M) {
  149. this.$message.error('上传头像图片大小不能超过 2MB!');
  150. }
  151. return isJPG && isLt2M;
  152. },
  153. // 点击删除
  154. clickDel(i, item) {
  155. const id = item.id
  156. this.$confirm('此操作将永久删除, 是否继续?', '提示', {
  157. confirmButtonText: '确定',
  158. cancelButtonText: '取消',
  159. type: 'warning'
  160. }).then(async () => {
  161. const res = await this.$post('/api/admin/developer/deleteRecommendDeveloper', { id });
  162. if(!res) return;
  163. this.$message({
  164. type: 'success',
  165. message: '删除成功!'
  166. });
  167. this.getTableData()
  168. }).catch(() => {
  169. this.$message({
  170. type: 'info',
  171. message: '已取消删除'
  172. });
  173. });
  174. },
  175. // 点击编辑
  176. clickEdit(i, { uid, order, url, id }) {
  177. // 获取编辑信息, 现在自带的全, 暂时不用了
  178. // 接口:/api/admin/developer/getRecommendDeveloper
  179. // 参数:id int 列表每条记录的id(不是uid)
  180. this.ruleForm = { uid, order, url, id };
  181. this.isEdit = true;
  182. this.centerDialogVisible = true;
  183. },
  184. // 点击用户
  185. clickUID(i) {
  186. window.open(i.seo_uri)
  187. },
  188. // 根据状态显示图表样式
  189. tableRowClassName({ row, rowIndex }) {
  190. let className = ''
  191. if(row.p_status_name === '已结算') className = 'success-row'
  192. return className
  193. },
  194. // 格式化列表数据
  195. formatTableData(data) {
  196. return data.map(i => ({
  197. ...i,
  198. }))
  199. },
  200. // 获取列表数据
  201. async getTableData(page = 1) {
  202. this.tableData = []
  203. const res = await this.$post('/api/admin/developer/getRecommendList', { page, page_size: 9 }) // page_size 解决一个迷 bug, 后端要求添加
  204. // console.log(res)
  205. const data = res.data.list
  206. this.tableData = this.formatTableData(data)
  207. this.totalCount = Number(data.total)
  208. this.totalPage = data.totalPage
  209. }
  210. }
  211. }
  212. </script>
  213. <style scoped>
  214. .table {
  215. height: calc(100% - 40px);
  216. }
  217. .avatar-uploader .el-upload {
  218. border: 1px dashed #d9d9d9;
  219. border-radius: 6px;
  220. cursor: pointer;
  221. position: relative;
  222. overflow: hidden;
  223. }
  224. .avatar-uploader .el-upload:hover {
  225. border-color: #409eff;
  226. }
  227. .avatar-uploader-icon {
  228. font-size: 28px;
  229. color: #8c939d;
  230. width: 178px;
  231. height: 178px;
  232. line-height: 178px;
  233. text-align: center;
  234. }
  235. .avatar {
  236. width: 178px;
  237. height: 178px;
  238. display: block;
  239. }
  240. </style>