dev_show.vue 6.9 KB

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