teacherButton.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <div>
  3. <!-- 搜索标题 -->
  4. <auth auths="news/add">
  5. <el-button
  6. @click="openTeaching('create')"
  7. type="primary"
  8. style="margin-bottom:20px"
  9. >
  10. 新建
  11. </el-button>
  12. </auth>
  13. <!-- 搜索标题 -->
  14. <save-form
  15. :inline="true"
  16. class="searchForm"
  17. saveKey="contentKnowledge"
  18. @submit="search"
  19. :model="searchForm"
  20. >
  21. <el-form-item prop="subType">
  22. <el-select
  23. v-model="searchForm.subType"
  24. clearable
  25. placeholder="请选择分类"
  26. >
  27. <el-option
  28. v-for="item in typeList"
  29. :key="item.id"
  30. :label="item.name"
  31. :value="item.id"
  32. ></el-option>
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button native-type="submit" type="danger">搜索</el-button>
  37. </el-form-item>
  38. </save-form>
  39. <!-- 列表 -->
  40. <div class="tableWrap">
  41. <el-table
  42. :data="tableList"
  43. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  44. >
  45. <el-table-column align="center" label="封面图">
  46. <template slot-scope="scope">
  47. <img class="bannerImg" :src="scope.row.coverImage" alt="" />
  48. </template>
  49. </el-table-column>
  50. <el-table-column align="center" prop="title" label="标题">
  51. </el-table-column>
  52. <el-table-column align="center" label="跳转链接">
  53. <template slot-scope="scope">
  54. <overflow-text
  55. width="100%"
  56. :text="scope.row.linkUrl"
  57. ></overflow-text>
  58. <!-- {{ scope.row.linkUrl + '/' + scope.row.id }} -->
  59. </template>
  60. </el-table-column>
  61. <el-table-column align="center" prop="remark" label="是否使用">
  62. <template slot-scope="scope">
  63. {{ scope.row.status == 1 ? "是" : "否" }}
  64. </template>
  65. </el-table-column>
  66. <el-table-column align="center" prop="subType" label="分类">
  67. <template slot-scope="scope">
  68. {{ formatSubType(scope.row.subType) }}
  69. </template>
  70. </el-table-column>
  71. <el-table-column align="center" prop="memo" label="版本号">
  72. </el-table-column>
  73. <el-table-column align="center" prop="order" label="排序">
  74. </el-table-column>
  75. <el-table-column align="center" label="操作">
  76. <template slot-scope="scope">
  77. <div>
  78. <auth auths="news/update" style="margin-left: 10px">
  79. <el-button
  80. @click="openTeaching('update', scope.row)"
  81. v-if="!scope.row.memo || permission('banner/copyrightbtn')"
  82. type="text"
  83. >修改</el-button
  84. >
  85. <div
  86. style="display: inline-block"
  87. v-if="!scope.row.memo || permission('banner/copyrightbtn')"
  88. >
  89. <el-button
  90. v-if="scope.row.status == 1"
  91. @click="onStop(scope.row, 0)"
  92. type="text"
  93. >停用</el-button
  94. >
  95. <el-button v-else @click="onStop(scope.row, 1)" type="text"
  96. >启用</el-button
  97. >
  98. </div>
  99. </auth>
  100. <auth auths="news/del">
  101. <el-button
  102. @click="onDel(scope.row)"
  103. v-if="!scope.row.memo || permission('banner/copyrightbtn')"
  104. type="text"
  105. >删除</el-button
  106. >
  107. </auth>
  108. </div>
  109. </template>
  110. </el-table-column>
  111. </el-table>
  112. <pagination
  113. saveKey="contentKnowledge"
  114. sync
  115. :total.sync="pageInfo.total"
  116. :page.sync="pageInfo.page"
  117. :limit.sync="pageInfo.limit"
  118. :page-sizes="pageInfo.page_size"
  119. @pagination="getList"
  120. />
  121. </div>
  122. <el-dialog
  123. :title="formTitle[pageType]"
  124. :visible.sync="teacherStatus"
  125. width="500px"
  126. >
  127. <el-form :model="form" ref="form" label-width="80px">
  128. <el-form-item
  129. label="标题"
  130. prop="title"
  131. :rules="[
  132. {
  133. required: true,
  134. message: '请输入标题',
  135. trigger: 'blur'
  136. }
  137. ]"
  138. >
  139. <el-input
  140. v-model.trim="form.title"
  141. placeholder="请输入标题"
  142. ></el-input>
  143. </el-form-item>
  144. <el-form-item label="排序值" prop="order">
  145. <el-input
  146. v-model.trim="form.order"
  147. placeholder="请输入排序值"
  148. ></el-input>
  149. </el-form-item>
  150. <el-form-item label="链接地址" prop="linkUrl">
  151. <el-input
  152. v-model.trim="form.linkUrl"
  153. placeholder="请输入链接地址"
  154. ></el-input>
  155. </el-form-item>
  156. <el-form-item label="版本号" prop="memo">
  157. <el-input v-model="form.memo" placeholder="请输入版本号"></el-input>
  158. </el-form-item>
  159. <el-form-item
  160. label="分类"
  161. prop="subType"
  162. :rules="[
  163. { required: true, message: '请选择分类', trigger: 'change' }
  164. ]"
  165. >
  166. <el-select
  167. v-model="form.subType"
  168. style="width: 100% !important"
  169. placeholder="请选择分类"
  170. >
  171. <el-option
  172. v-for="item in typeList"
  173. :key="item.id"
  174. :label="item.name"
  175. :value="item.id"
  176. ></el-option>
  177. </el-select>
  178. </el-form-item>
  179. <el-form-item
  180. label="封面图"
  181. prop="coverImage"
  182. :rules="[
  183. { required: true, message: '请上传封面图', trigger: 'blur' }
  184. ]"
  185. >
  186. <image-cropper
  187. :options="cropperOptions"
  188. :imgSize="2"
  189. showSize
  190. :imageUrl="form.coverImage"
  191. @crop-upload-success="cropSuccess"
  192. />
  193. <p class="imageSize">图片不能超过 2M;图片尺寸:80*80;</p>
  194. </el-form-item>
  195. </el-form>
  196. <div slot="footer" class="dialog-footer">
  197. <el-button @click="teacherStatus = false">取 消</el-button>
  198. <el-button type="primary" @click="onSubmit">确 定</el-button>
  199. </div>
  200. </el-dialog>
  201. </div>
  202. </template>
  203. <script>
  204. import {
  205. newsList,
  206. newsUpdate,
  207. newsDel,
  208. newsTypeList,
  209. newsAdd
  210. } from "@/api/contentManager";
  211. import ImageCropper from "@/components/ImageCropper";
  212. import pagination from "@/components/Pagination/index";
  213. import cleanDeep from "clean-deep";
  214. import { permission } from "@/utils/directivePage";
  215. export default {
  216. name: "teacherButton",
  217. components: {
  218. pagination,
  219. ImageCropper
  220. },
  221. data() {
  222. return {
  223. teacherStatus: false,
  224. formTitle: {
  225. create: "新建老师端按钮",
  226. update: "修改老师端按钮"
  227. },
  228. pageType: "create",
  229. cropperOptions: {
  230. autoCrop: true, //是否默认生成截图框
  231. autoCropWidth: 88, //默认生成截图框宽度
  232. autoCropHeight: 88, //默认生成截图框高度
  233. fixedBox: true, //是否固定截图框大小 不允许改变
  234. previewsCircle: false, //预览图是否是圆形
  235. full: true, // 是否输出原图比例的截图
  236. title: "上传图片" //模态框上显示的标题
  237. },
  238. form: {
  239. title: "",
  240. order: null,
  241. linkUrl: "",
  242. coverImage: "",
  243. subType: null,
  244. type: 23,
  245. memo: "",
  246. status: 1,
  247. content: ""
  248. },
  249. searchForm: {
  250. subType: null
  251. },
  252. tableList: [],
  253. teacherId: this.$route.query.teacherId,
  254. pageInfo: {
  255. // 分页规则
  256. limit: 10, // 限制显示条数
  257. page: 1, // 当前页
  258. total: 1, // 总条数
  259. page_size: [10, 20, 40, 50] // 选择限制显示条数
  260. },
  261. typeList: [] // 子分类
  262. };
  263. },
  264. async mounted() {
  265. await newsTypeList({ parentId: 23 }).then(res => {
  266. if (res.code == 200) {
  267. this.typeList = res.data;
  268. }
  269. });
  270. this.getList();
  271. },
  272. methods: {
  273. //上传图片成功
  274. cropSuccess(data) {
  275. this.form.coverImage = data.data.url;
  276. },
  277. onSubmit() {
  278. this.$refs["form"].validate(async valid => {
  279. if (valid) {
  280. let form = {
  281. ...this.form
  282. };
  283. if (this.pageType == "create") {
  284. if (form.id) {
  285. // 判断有没有Id,如果有则删除
  286. delete form.id;
  287. }
  288. await newsAdd(form).then(res => {
  289. this.messageTips("添加", res);
  290. });
  291. } else if (this.pageType == "update") {
  292. await newsUpdate(form).then(res => {
  293. this.messageTips("修改", res);
  294. });
  295. }
  296. }
  297. });
  298. },
  299. messageTips(title, res) {
  300. if (res.code == 200) {
  301. this.$message.success(title + "成功");
  302. this.getList();
  303. this.teacherStatus = false;
  304. } else {
  305. this.$message.error(res.msg);
  306. }
  307. },
  308. search() {
  309. this.pageInfo.page = 1;
  310. this.getList();
  311. },
  312. permission(str) {
  313. return permission(str);
  314. },
  315. getList() {
  316. let params = {
  317. clientName: "manage",
  318. subType: this.searchForm.subType,
  319. rows: this.pageInfo.limit,
  320. page: this.pageInfo.page,
  321. type: 23
  322. };
  323. newsList(cleanDeep(params)).then(res => {
  324. if (res.code == 200) {
  325. this.tableList = res.data.rows;
  326. this.pageInfo.total = res.data.total;
  327. }
  328. });
  329. },
  330. openTeaching(type, rows) {
  331. this.teacherStatus = true;
  332. this.$nextTick(() => {
  333. if (this.$refs["form"]) {
  334. this.$refs["form"].resetFields();
  335. }
  336. this.pageType = type;
  337. if (type == "update") {
  338. this.form.id = rows.id;
  339. this.form.title = rows.title;
  340. this.form.order = rows.order;
  341. this.form.linkUrl = rows.linkUrl;
  342. this.form.coverImage = rows.coverImage;
  343. this.form.subType = rows.subType;
  344. }
  345. });
  346. },
  347. onDel(row) {
  348. // 删除
  349. this.$confirm("确定是否删除?", "提示", {
  350. confirmButtonText: "确定",
  351. cancelButtonText: "取消",
  352. type: "warning"
  353. })
  354. .then(() => {
  355. newsDel({ id: row.id }).then(res => {
  356. if (res.code == 200) {
  357. this.$message.success("删除成功");
  358. this.getList();
  359. } else {
  360. this.$message.error(res.msg);
  361. }
  362. });
  363. })
  364. .catch(() => {});
  365. },
  366. onStop(row, status) {
  367. // 停止
  368. // newsUpdate
  369. let tempStr = ["停用", "启用"];
  370. newsUpdate({
  371. id: row.id,
  372. status: status
  373. }).then(res => {
  374. if (res.code == 200) {
  375. this.$message.success(tempStr[status] + "成功");
  376. this.getList();
  377. } else {
  378. this.$message.error(res.msg);
  379. }
  380. });
  381. },
  382. formatSubType(val) {
  383. let tempName = null;
  384. this.typeList.forEach(item => {
  385. if (item.id == val) {
  386. tempName = item.name;
  387. }
  388. });
  389. return tempName;
  390. }
  391. }
  392. };
  393. </script>
  394. <style lang="scss" scoped>
  395. .bannerImg {
  396. height: 60px;
  397. }
  398. </style>