materialsList.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. <template>
  2. <el-tabs v-model="activeName" @tab-click="handleClick">
  3. <el-tab-pane label="分类管理" name="first">
  4. <div style="float: right;margin-right:2%;">
  5. <el-button style='margin: 10px 0;' :disabled="!isAuth('materialsList:add')" size="mini" type="primary"
  6. icon="document" @click="addNotice">添加分类</el-button>
  7. </div>
  8. <el-table v-loading="tableDataLoading" :data="tableData">
  9. <el-table-column fixed prop="id" label="编号" width="80">
  10. </el-table-column>
  11. <el-table-column prop="classifyName" label="分类名称">
  12. </el-table-column>
  13. <!-- <el-table-column
  14. prop="remark"
  15. label="备注">
  16. </el-table-column> -->
  17. <el-table-column prop="createTime" label="创建时间">
  18. </el-table-column>
  19. <el-table-column label="操作" width="150">
  20. <template slot-scope="scope">
  21. <el-button size="mini" type="primary" :disabled="!isAuth('materialsList:update')"
  22. @click="updates(scope.$index, scope.row)">编辑
  23. </el-button>
  24. <el-button size="mini" type="danger" :disabled="!isAuth('materialsList:delete')"
  25. @click="deletes(scope.row)">删除
  26. </el-button>
  27. </template>
  28. </el-table-column>
  29. </el-table>
  30. <!-- 添加弹框 -->
  31. <el-dialog title="添加分类" :visible.sync="dialogFormVisible" center>
  32. <div style="margin-bottom: 10px;">
  33. <span style="width: 200px;display: inline-block;text-align: right;">分类名称:</span>
  34. <el-input style="width:50%;" v-model="classifyName" placeholder="请输入分类名称"></el-input>
  35. </div>
  36. <!-- <div style="margin-bottom: 10px;">
  37. <span style="width: 200px;display: inline-block;text-align: right;">备注:</span>
  38. <el-input style="width: 50%;" v-model="remark" placeholder="请输入备注"></el-input>
  39. </div> -->
  40. <div slot="footer" class="dialog-footer">
  41. <el-button @click="dialogFormVisible = false">取 消</el-button>
  42. <el-button type="primary" @click="releasNoticeTo()">确 定</el-button>
  43. </div>
  44. </el-dialog>
  45. <!-- 修改弹框 -->
  46. <el-dialog title="修改分类" :visible.sync="dialogFormVisible1" center>
  47. <el-form :model="form">
  48. <el-form-item label="分类名称:" :label-width="formLabelWidth">
  49. <el-input v-model="form.classifyName" style="width:65%;"></el-input>
  50. </el-form-item>
  51. </el-form>
  52. <div slot="footer" class="dialog-footer">
  53. <el-button @click="dialogFormVisible1 = false">取 消</el-button>
  54. <el-button type="primary" @click="amendNoticeTo()">确 定</el-button>
  55. </div>
  56. </el-dialog>
  57. </el-tab-pane>
  58. <el-tab-pane label="文章管理" name="second">
  59. <div style="float: right;margin-right:2%;">
  60. <el-button style='margin: 10px 0;height:35px;' :disabled="!isAuth('materialsList:add')" size="mini"
  61. type="primary" icon="document" @click="addNoticewz">添加文章</el-button>&nbsp;&nbsp;&nbsp;&nbsp;
  62. <el-select v-model="classifyId" placeholder="请选择类型" style="width:150px;" @change="articleSelect(classifyId)">
  63. <el-option v-for="(item,index) in classifyIds" :key="item.index" :label="item.classifyName" :value="item.id">
  64. </el-option>
  65. </el-select>
  66. </div>
  67. <el-table v-loading="tableDataLoading" :data="tableData">
  68. <el-table-column prop="id" label="编号" width="80">
  69. </el-table-column>
  70. <el-table-column prop="title" label="标题" width="120">
  71. </el-table-column>
  72. <el-table-column prop="articleUrl" label="链接">
  73. </el-table-column>
  74. <el-table-column prop="picture" label="图片">
  75. <template slot-scope="scope">
  76. <img :src="scope.row.picture" alt="" width="60" height="60">
  77. </template>
  78. </el-table-column>
  79. <el-table-column prop="content" label="内容">
  80. </el-table-column>
  81. <el-table-column prop="createTime" label="创建时间" width="160">
  82. </el-table-column>
  83. <el-table-column label="操作">
  84. <template slot-scope="scope">
  85. <el-button size="mini" type="primary" :disabled="!isAuth('materialsList:update')"
  86. @click="updateswz(scope.$index, scope.row)">编辑
  87. </el-button>
  88. <el-button size="mini" type="danger" :disabled="!isAuth('materialsList:delete')"
  89. @click="deleteswz(scope.row)">删除
  90. </el-button>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. <!-- 添加弹框 -->
  95. <el-dialog title="添加文章" :visible.sync="dialogFormVisible2" center>
  96. <div style="margin-bottom: 10px;display: flex;">
  97. <span style="width: 200px;display: inline-block;text-align: right;">文章图片:</span>
  98. <div
  99. style=" width:148px;height:148px;border: 1px dashed #c0ccda;border-radius: 6px;text-align: center;line-height: 148px;">
  100. <el-upload class="avatar-uploader" v-model="picture"
  101. action="https://mxys.chuanghai-tech.com/sqx_fast/alioss/upload" :show-file-list="false"
  102. :on-success="handleAvatarSuccess">
  103. <img v-if="picture" :src="picture" class="avatar"
  104. style="border-radius: 6px;width: 148px;height: 148px;" />
  105. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  106. </el-upload>
  107. </div>
  108. </div>
  109. <div style="margin-bottom: 10px;">
  110. <span style="width: 200px;display: inline-block;text-align: right;">文章标题:</span>
  111. <el-input style="width: 50%;" v-model="title" placeholder="请输入文章标题"></el-input>
  112. </div>
  113. <div style="margin-bottom: 10px;">
  114. <span style="width: 200px;display: inline-block;text-align: right;">跳转链接:</span>
  115. <el-input style="width: 50%;" v-model="articleUrl" placeholder="请输入跳转链接"></el-input>
  116. </div>
  117. <div style="margin-bottom: 10px;p">
  118. <span style="width: 200px;display: inline-block;text-align: right;position: relative;top: -65px;">文章内容:</span>
  119. <el-input style="width: 50%;" type="textarea" rows="4" v-model="content" placeholder="请输入内容"></el-input>
  120. </div>
  121. <div slot="footer" class="dialog-footer">
  122. <el-button @click="dialogFormVisible2 = false">取 消</el-button>
  123. <el-button type="primary" @click="releasNoticeTowz()">确 定</el-button>
  124. </div>
  125. </el-dialog>
  126. <!-- 修改弹框 -->
  127. <el-dialog title="修改文章" :visible.sync="dialogFormVisible3" center>
  128. <el-form :model="form">
  129. <el-form-item label="文章图片:" :label-width="formLabelWidth">
  130. <div
  131. style=" width:148px;height:148px;border: 1px dashed #c0ccda;border-radius: 6px;text-align: center;line-height: 148px;">
  132. <el-upload class="avatar-uploader" v-model="picture"
  133. action="https://mxys.chuanghai-tech.com/sqx_fast/alioss/upload" :show-file-list="false"
  134. :on-success="handleAvatarSuccess2">
  135. <img v-if="formwz.picture" :src="formwz.picture" class="avatar"
  136. style="border-radius: 6px;width: 148px;height: 148px;" />
  137. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  138. </el-upload>
  139. </div>
  140. </el-form-item>
  141. <el-form-item label="文章标题:" :label-width="formLabelWidth">
  142. <el-input v-model="formwz.title" style="width:65%;"></el-input>
  143. </el-form-item>
  144. <el-form-item label="跳转链接:" :label-width="formLabelWidth">
  145. <el-input v-model="formwz.articleUrl" style="width:65%;"></el-input>
  146. </el-form-item>
  147. <el-form-item label="文章内容:" :label-width="formLabelWidth">
  148. <el-input type="textarea" rows="4" v-model="formwz.content" style="width:65%;"></el-input>
  149. </el-form-item>
  150. </el-form>
  151. <div slot="footer" class="dialog-footer">
  152. <el-button @click="dialogFormVisible3 = false">取 消</el-button>
  153. <el-button type="primary" @click="amendNoticeTowz()">确 定</el-button>
  154. </div>
  155. </el-dialog>
  156. </el-tab-pane>
  157. </el-tabs>
  158. </template>
  159. <script>
  160. export default {
  161. data() {
  162. return {
  163. limit: 5,
  164. page: 1,
  165. state: 1,
  166. sort: 0,
  167. remark: '',
  168. createTime: '',
  169. classifyName: '',
  170. id: '',
  171. classifyId: 1,
  172. classifyIds: [],
  173. form: {
  174. id: '',
  175. state: '',
  176. sort: '',
  177. classifyName: '',
  178. createTime: '',
  179. remark: ''
  180. },
  181. formwz: {
  182. id: '',
  183. picture: '',
  184. articleUrl: '',
  185. content: '',
  186. title: '',
  187. classifyId: '',
  188. createTime: ''
  189. },
  190. info: {
  191. stockDate: this.getNowTime(), //日期
  192. },
  193. picture: '',
  194. picture2: '',
  195. articleUrl: '',
  196. content: '',
  197. title: '',
  198. formLabelWidth: '200px',
  199. activeName: 'first',
  200. tableDataLoading: false,
  201. dialogFormVisible1: false,
  202. dialogFormVisible: false,
  203. dialogFormVisible2: false,
  204. dialogFormVisible3: false,
  205. tableData: [],
  206. }
  207. },
  208. methods: {
  209. //处理默认选中当前日期
  210. getNowTime() {
  211. var now = new Date();
  212. var year = now.getFullYear(); //得到年份
  213. var month = now.getMonth(); //得到月份
  214. var date = now.getDate(); //得到日期
  215. var hh = now.getHours() < 10 ? "0" + now.getHours() : now.getHours();
  216. var mm = now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes();
  217. var ss = now.getSeconds() < 10 ? "0" + now.getSeconds() : now.getSeconds();
  218. month = month + 1;
  219. month = month.toString().padStart(2, "0");
  220. date = date.toString().padStart(2, "0");
  221. var defaultDate = `${year}-${month}-${date} ${hh}:${mm}:${ss}`;
  222. return defaultDate;
  223. this.$set(this.info, "stockDate", defaultDate);
  224. },
  225. handleClick(tab, event) {
  226. if (tab._props.label == '分类管理') {
  227. this.dataSelect()
  228. }
  229. if (tab._props.label == '文章管理') {
  230. this.classifyId = 1
  231. this.articleSelect()
  232. }
  233. },
  234. handleAvatarSuccess(file) {
  235. this.picture = file.data;
  236. },
  237. handleAvatarSuccess2(file2) {
  238. this.formwz.picture = file2.data;
  239. },
  240. // 添加分类弹框
  241. addNotice() {
  242. this.dialogFormVisible = true
  243. },
  244. // 添加分类
  245. releasNoticeTo() {
  246. if (this.classifyName == '') {
  247. this.$notify({
  248. title: '提示',
  249. duration: 1800,
  250. message: '请选择分类名称',
  251. type: 'warning'
  252. });
  253. return
  254. }
  255. this.$http({
  256. url: this.$http.adornUrl('article/saveArticleClassify'),
  257. method: 'post',
  258. data: this.$http.adornData({
  259. 'state': this.state,
  260. 'sort': this.sort,
  261. 'remark': this.remark,
  262. 'classifyName': this.classifyName,
  263. 'createTime': this.info.stockDate,
  264. })
  265. }).then(({
  266. data
  267. }) => {
  268. this.dialogFormVisible = false
  269. this.$message({
  270. message: '操作成功',
  271. type: 'success',
  272. duration: 1500,
  273. onClose: () => {
  274. this.classifyName = ''
  275. this.dataSelect()
  276. }
  277. })
  278. })
  279. },
  280. // 编辑分类弹框
  281. updates(index, rows) {
  282. this.form.state = rows.state;
  283. this.form.sort = rows.state;
  284. this.dialogFormVisible1 = true;
  285. this.form.id = rows.id;
  286. this.form.classifyName = rows.classifyName;
  287. this.form.remark = rows.remark;
  288. this.form.createTime = rows.createTime;
  289. },
  290. // 修改类别
  291. amendNoticeTo() {
  292. this.$http({
  293. url: this.$http.adornUrl(`article/updateClassifyName/${this.form.id}/${this.form.classifyName}`),
  294. method: 'post',
  295. data: this.$http.adornData({})
  296. }).then(({
  297. data
  298. }) => {
  299. this.dialogFormVisible1 = false
  300. this.$message({
  301. message: '操作成功',
  302. type: 'success',
  303. duration: 1500,
  304. onClose: () => {
  305. this.dataSelect()
  306. }
  307. })
  308. })
  309. },
  310. // 删除分类
  311. deletes(row) {
  312. this.$confirm(`确定删除此条信息?`, '提示', {
  313. confirmButtonText: '确定',
  314. cancelButtonText: '取消',
  315. type: 'warning'
  316. }).then(() => {
  317. this.$http({
  318. url: this.$http.adornUrl(`article/deleteArticleClassifyById?articleClassifyId=${row.id}`),
  319. method: 'post',
  320. data: this.$http.adornData({})
  321. }).then(({
  322. data
  323. }) => {
  324. this.$message({
  325. message: '删除成功',
  326. type: 'success',
  327. duration: 1500,
  328. onClose: () => {
  329. this.name = '';
  330. this.dataSelect()
  331. }
  332. })
  333. })
  334. }).catch(() => {})
  335. },
  336. // 添加文章弹框
  337. addNoticewz() {
  338. this.dialogFormVisible2 = true
  339. },
  340. // 添加文章
  341. releasNoticeTowz() {
  342. if (this.title == '') {
  343. this.$notify({
  344. title: '提示',
  345. duration: 1800,
  346. message: '请输入文章标题',
  347. type: 'warning'
  348. });
  349. return
  350. }
  351. if (this.articleUrl == '') {
  352. this.$notify({
  353. title: '提示',
  354. duration: 1800,
  355. message: '请输入跳转链接',
  356. type: 'warning'
  357. });
  358. return
  359. }
  360. if (this.content == '') {
  361. this.$notify({
  362. title: '提示',
  363. duration: 1800,
  364. message: '请输入内容',
  365. type: 'warning'
  366. });
  367. return
  368. }
  369. this.$http({
  370. url: this.$http.adornUrl('article/addArticle'),
  371. method: 'post',
  372. data: this.$http.adornData({
  373. 'articleUrl': this.articleUrl,
  374. 'classifyId': this.classifyId,
  375. 'content': this.content,
  376. 'createTime': this.info.stockDate,
  377. 'picture': this.picture,
  378. 'state': this.state,
  379. 'title': this.title,
  380. })
  381. }).then(({
  382. data
  383. }) => {
  384. this.dialogFormVisible2 = false
  385. this.$message({
  386. message: '操作成功',
  387. type: 'success',
  388. duration: 1500,
  389. onClose: () => {
  390. this.title = ''
  391. this.articleUrl = ''
  392. this.content = ''
  393. this.picture = ''
  394. this.articleSelect()
  395. }
  396. })
  397. })
  398. },
  399. // 编辑文章弹框
  400. updateswz(index, rows) {
  401. this.formwz.picture = rows.picture;
  402. this.dialogFormVisible3 = true;
  403. this.formwz.id = rows.id;
  404. this.formwz.classifyId = rows.classifyId
  405. this.formwz.articleUrl = rows.articleUrl;
  406. this.formwz.content = rows.content;
  407. this.formwz.title = rows.title;
  408. this.formwz.createTime = rows.createTime;
  409. },
  410. // 修改文章
  411. amendNoticeTowz() {
  412. this.$http({
  413. url: this.$http.adornUrl('article/updateArticle'),
  414. method: 'post',
  415. data: this.$http.adornData({
  416. 'id': this.formwz.id,
  417. 'picture': this.formwz.picture,
  418. 'articleUrl': this.formwz.articleUrl,
  419. 'content': this.formwz.content,
  420. 'classifyId': this.formwz.classifyId,
  421. 'title': this.formwz.title,
  422. 'createTime': this.info.stockDate,
  423. })
  424. }).then(({
  425. data
  426. }) => {
  427. this.dialogFormVisible3 = false
  428. this.$message({
  429. message: '操作成功',
  430. type: 'success',
  431. duration: 1500,
  432. onClose: () => {
  433. this.articleSelect()
  434. }
  435. })
  436. })
  437. },
  438. // 删除文章
  439. deleteswz(row) {
  440. this.$confirm(`确定删除此条信息?`, '提示', {
  441. confirmButtonText: '确定',
  442. cancelButtonText: '取消',
  443. type: 'warning'
  444. }).then(() => {
  445. this.$http({
  446. url: this.$http.adornUrl(`article/deleteArticle?articleId=${row.id}`),
  447. method: 'post',
  448. data: this.$http.adornData({})
  449. }).then(({
  450. data
  451. }) => {
  452. this.$message({
  453. message: '删除成功',
  454. type: 'success',
  455. duration: 1500,
  456. onClose: () => {
  457. this.name = '';
  458. this.articleSelect()
  459. }
  460. })
  461. })
  462. }).catch(() => {})
  463. },
  464. // 获取分类管理数据
  465. dataSelect() {
  466. this.tableDataLoading = true
  467. this.$http({
  468. url: this.$http.adornUrl('article/selectArticleClassifyList'),
  469. method: 'get',
  470. params: this.$http.adornParams({})
  471. }).then(({
  472. data
  473. }) => {
  474. this.tableDataLoading = false
  475. let returnData = data.data;
  476. this.tableData = returnData
  477. this.classifyIds = returnData
  478. })
  479. },
  480. // 获取文章管理数据
  481. articleSelect() {
  482. this.tableDataLoading = true
  483. this.$http({
  484. url: this.$http.adornUrl('article/selectArticleList'),
  485. method: 'get',
  486. params: this.$http.adornParams({
  487. 'classifyId': this.classifyId
  488. })
  489. }).then(({
  490. data
  491. }) => {
  492. this.tableDataLoading = false
  493. let returnData = data.data;
  494. this.tableData = returnData
  495. })
  496. },
  497. },
  498. mounted() {
  499. this.dataSelect()
  500. }
  501. };
  502. </script>
  503. <style>
  504. </style>