index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <!-- 运营管理 上传壁纸 -->
  2. <template>
  3. <div class="app-container">
  4. <!-- 搜索 -->
  5. <el-form inline size="mini">
  6. <el-form-item>
  7. <el-button
  8. type="primary"
  9. icon="el-icon-plus"
  10. plain
  11. @click="getDialog(0, null)"
  12. v-hasPermi="['operation:piano:add']"
  13. >新增</el-button
  14. >
  15. </el-form-item>
  16. </el-form>
  17. <!-- 列表 -->
  18. <el-table :data="tableData" v-loading="loading">
  19. <!-- <el-table-column
  20. label="排序"
  21. align="center"
  22. type="index"
  23. show-overflow-tooltip
  24. /> -->
  25. <el-table-column label="排序" align="center" width="200px" prop="sort" />
  26. <el-table-column label="图片" align="center" width="100px">
  27. <template slot-scope="scope">
  28. <el-image :src="scope.row.pic" />
  29. </template>
  30. </el-table-column>
  31. <el-table-column label="创建时间" align="center" prop="createTimeStr" />
  32. <el-table-column label="操作" align="center">
  33. <template slot-scope="scope">
  34. <span style="margin: 0 10px">
  35. <el-button
  36. type="text"
  37. @click="getDialog(1, scope.row)"
  38. v-hasPermi="['operation:piano:edit']"
  39. >编辑</el-button
  40. >
  41. <el-button
  42. type="delete"
  43. @click="getDelete(scope.row)"
  44. v-hasPermi="['operation:piano:delete']"
  45. >删除</el-button
  46. >
  47. </span>
  48. </template>
  49. </el-table-column>
  50. </el-table>
  51. <!-- 弹窗 -->
  52. <el-dialog
  53. :visible.sync="dialogVisible"
  54. :title="dialogTitle"
  55. width="500px"
  56. :before-close="getDialogClose"
  57. >
  58. <el-form
  59. :model="dialogData"
  60. ref="dialogData"
  61. :rules="rules"
  62. label-width="auto"
  63. >
  64. <el-form-item label="上传:" prop="pic">
  65. <Upload
  66. listType="picture-card"
  67. width="480"
  68. height="480"
  69. :url="dialogData.pic"
  70. @upload="uploadCode($event, 'pic')"
  71. />
  72. </el-form-item>
  73. <el-form-item label="排序:" prop="sort">
  74. <el-input-number v-model="dialogData.sort" :min="1" />
  75. </el-form-item>
  76. <el-form-item label="应用类型:" prop="applicationType">
  77. <input type="checkbox" v-model="isChecked1" /> 小程序
  78. <input
  79. type="checkbox"
  80. style="margin-left: 30px"
  81. v-model="isChecked2"
  82. />
  83. APP
  84. </el-form-item>
  85. </el-form>
  86. <div slot="footer">
  87. <el-button @click="getDialogClose">取消</el-button>
  88. <!-- <el-button @click="getDialogClose">取消</el-button> -->
  89. <el-button type="primary" @click="getDialogSubmit">确定</el-button>
  90. </div>
  91. </el-dialog>
  92. <pagination
  93. v-show="total > 0"
  94. :total="total"
  95. :page.sync="form.pageNum"
  96. :limit.sync="form.pageSize"
  97. @pagination="getList"
  98. />
  99. </div>
  100. </template>
  101. <script>
  102. import { add, deletes, edit, list } from "@/api/operation/piano";
  103. import { currentMixin, devMixin, disabledMixin } from "@/mixin/index";
  104. import { dialogCallBack } from "@/utils/DialogUtil";
  105. export default {
  106. mixins: [devMixin, currentMixin, disabledMixin],
  107. data() {
  108. return {
  109. isChecked1: false,
  110. isChecked2: false,
  111. // 遮罩层
  112. loading: false,
  113. // 表单
  114. form: {
  115. pageNum: 1,
  116. pageSize: 10,
  117. },
  118. // 总数据
  119. total: 0,
  120. // 列表
  121. tableData: [],
  122. // 弹窗
  123. dialogVisible: false,
  124. dialogTitle: "新增",
  125. picTemp: "",
  126. dialogData: {
  127. sort: 1,
  128. },
  129. ///弹窗类型
  130. dialogStatus: 0,
  131. // 表单验证
  132. rules: {
  133. pic: [{ required: true, message: "请上传图片", trigger: "change" }],
  134. sort: [{ required: true, message: "请选择排序", trigger: "blur" }],
  135. applicationType: [
  136. { required: true, message: "请选择应用类型", trigger: "blur" },
  137. ],
  138. },
  139. };
  140. },
  141. watch: {},
  142. mounted() {
  143. this.getList();
  144. },
  145. methods: {
  146. addData() {},
  147. // 列表
  148. getList() {
  149. this.loading = true;
  150. list(this.form).then((res) => {
  151. if (res.code === 0) {
  152. this.tableData = res.data.records;
  153. this.total = res.data.total;
  154. this.loading = false;
  155. }
  156. });
  157. },
  158. // 弹窗
  159. async getDialog(status, row) {
  160. this.dialogVisible = true;
  161. this.dialogStatus = status;
  162. ///新增
  163. if (status == 0) {
  164. this.dialogData = { sort: 1 };
  165. }
  166. ///编辑
  167. else {
  168. this.dialogData = row;
  169. this.picTemp = this.dialogData.pic;
  170. var applicationType = this.dialogData.applicationType;
  171. this.isChecked1 = false;
  172. this.isChecked2 = false;
  173. if (applicationType != null && applicationType != "") {
  174. applicationType = applicationType.replace(/[\[\]]/g, "");
  175. // 使用split按逗号分割字符串
  176. let result = applicationType.split(",");
  177. if (result != null && result != "" && result.length > 0) {
  178. if (result.length == 2) {
  179. this.isChecked1 = true;
  180. this.isChecked2 = true;
  181. } else {
  182. if (result[0] == "0") {
  183. this.isChecked1 = true;
  184. } else {
  185. this.isChecked2 = true;
  186. }
  187. }
  188. } else {
  189. if (applicationType == 0) {
  190. this.isChecked1 = true;
  191. } else if (applicationType == 1) {
  192. this.isChecked2 = true;
  193. }
  194. }
  195. }
  196. }
  197. },
  198. // 删除
  199. getDelete(row) {
  200. var that = this;
  201. dialogCallBack(that, function () {
  202. that
  203. .$confirm(`是否删除?`, "提示:", {
  204. type: "warning",
  205. })
  206. .then(() => {
  207. deletes(row.id, 2).then((res) => {
  208. if (res.code === 0) {
  209. that.$message.success("删除成功!");
  210. that.getList();
  211. }
  212. });
  213. });
  214. });
  215. },
  216. // 取消
  217. getDialogClose() {
  218. this.dialogVisible = false;
  219. this.dialogData = { sort: 1 };
  220. // this.$refs.dialogData.resetFields();
  221. },
  222. // 上传
  223. uploadCode(e) {
  224. this.picTemp = e.file;
  225. if (e != null && e.file != "") {
  226. this.dialogData.pic = e.file;
  227. }
  228. },
  229. // 提交分类表单
  230. getDialogSubmit() {
  231. var that = this;
  232. var pic = this.picTemp;
  233. // var pic = that.dialogData.pic;
  234. if (pic == null || pic == "") {
  235. that.$message.success("请上传图片");
  236. return;
  237. }
  238. var sort = that.dialogData.sort;
  239. if (sort == null || sort == "") {
  240. that.$message.success("请选择排序");
  241. return;
  242. }
  243. if (!that.isChecked1 && !that.isChecked2) {
  244. that.$message.success("请选择应用类型");
  245. return;
  246. }
  247. if (that.isChecked1 && that.isChecked2) {
  248. that.dialogData.applicationType = "[0,1]";
  249. } else if (that.isChecked2) {
  250. that.dialogData.applicationType = "[1]";
  251. } else {
  252. that.dialogData.applicationType = "[0]";
  253. }
  254. ///新增
  255. if (that.dialogStatus == 0) {
  256. add(that.dialogData).then((res) => {
  257. if (res.code === 0) {
  258. that.$message.success("添加成功!");
  259. that.getDialogClose();
  260. that.getList();
  261. }
  262. });
  263. } else {
  264. edit(that.dialogData).then((res) => {
  265. if (res.code === 0) {
  266. that.$message.success("修改成功!");
  267. that.getDialogClose();
  268. that.getList();
  269. }
  270. });
  271. }
  272. },
  273. },
  274. };
  275. </script>