index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <div class="dashboard-container">
  3. <div class="dashboard-text">
  4. <el-button type="primary" @click="addList">增加项列表</el-button>
  5. <el-table
  6. :data="getRowItemData"
  7. style="width: 100%"
  8. >
  9. <el-table-column
  10. label="序号"
  11. width="60"
  12. prop="sort"
  13. />
  14. <el-table-column
  15. label="id"
  16. width="160"
  17. prop="id"
  18. />
  19. <el-table-column
  20. label="项目名称"
  21. width="150"
  22. prop="content"
  23. />
  24. <el-table-column
  25. label="项目icon"
  26. width="180"
  27. >
  28. <template slot-scope="scope">
  29. <img :src="scope.row.icon" style="width: 100%">
  30. </template>
  31. </el-table-column>
  32. <el-table-column
  33. label="跳转类型"
  34. width="80"
  35. >
  36. <template slot-scope="scope">
  37. <span>{{ targetType(scope.row.targetType) }}</span>
  38. </template>
  39. </el-table-column>
  40. <el-table-column
  41. label="状态"
  42. width="80"
  43. >
  44. <template slot-scope="scope">
  45. <span>{{ scope.row.status === 'HAS_ON_STOCK' ? '上架' : '下架' }}</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column
  49. label="创建时间"
  50. width="180"
  51. >
  52. <template slot-scope="scope">
  53. <span>{{ newDate(scope.row.gmtCreated) }}</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column
  57. label="修改时间"
  58. width="180"
  59. >
  60. <template slot-scope="scope">
  61. <span>{{ newDate(scope.row.gmtModified) }}</span>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="操作">
  65. <template slot-scope="scope">
  66. <el-button
  67. size="mini"
  68. @click="handleEdit(scope.$index, scope.row)"
  69. >修改</el-button>
  70. <el-button
  71. size="mini"
  72. @click="handleUp(scope.$index, scope.row)"
  73. >{{ scope.row.status === 'HAS_ON_STOCK' ? '下架' : '上架' }}</el-button>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <el-dialog title="首页项列表" :visible.sync="dialogFormVisible">
  78. <el-form ref="ruleForm" :model="form" :rules="rules">
  79. <el-form-item label="项目名称" :label-width="formLabelWidth" prop="content">
  80. <el-input v-model="form.content" autocomplete="off" clearable />
  81. </el-form-item>
  82. <el-form-item v-if="type === 'add'" label="icon" :label-width="formLabelWidth">
  83. <el-input v-model="form.icon" autocomplete="off" clearable />
  84. </el-form-item>
  85. <el-form-item v-if="type === 'add'" label="跳转类型" :label-width="formLabelWidth">
  86. <el-select v-model="form.targetType" placeholder="请选择">
  87. <el-option value="LIBRARY" label="图书馆课程" />
  88. <el-option value="PAY" label="知识付费" />
  89. <el-option value="TOPIC" label="专题" />
  90. <el-option value="SCHEDULE" label="课程表" />
  91. <el-option value="URL" label="URL" />
  92. </el-select>
  93. </el-form-item>
  94. <el-form-item label="排序" :label-width="formLabelWidth" prop="sort">
  95. <el-input v-model="form.sort" autocomplete="off" clearable />
  96. </el-form-item>
  97. <el-form-item v-if="type === 'add'" label="跳转地址" :label-width="formLabelWidth">
  98. <el-input v-model="form.targetContent" autocomplete="off" clearable />
  99. <el-tag type="danger">请输入Code</el-tag>
  100. </el-form-item>
  101. <el-form-item v-if="type === 'add'" label="状态" :label-width="formLabelWidth" prop="status">
  102. <el-select v-model="form.status" placeholder="请选择">
  103. <el-option value="NOT_ON_STOCK" label="下架" />
  104. <el-option value="HAS_ON_STOCK" label="上架" />
  105. </el-select>
  106. </el-form-item>
  107. </el-form>
  108. <div slot="footer" class="dialog-footer">
  109. <el-button @click="dialogFormVisible = false">取 消</el-button>
  110. <el-button type="primary" @click="handOk('ruleForm')">确 定</el-button>
  111. </div>
  112. </el-dialog>
  113. </div>
  114. </div>
  115. </template>
  116. <script>
  117. import { mapGetters } from 'vuex'
  118. export default {
  119. name: 'Dashboard',
  120. data() {
  121. return {
  122. form: {},
  123. dialogFormVisible: false,
  124. type: '',
  125. formLabelWidth: '120px',
  126. rules: {
  127. content: [
  128. { required: true, message: '请输入项目名称', trigger: 'blur' }
  129. ],
  130. icon: [
  131. { required: true, message: '请输入icon', trigger: 'blur' }
  132. ],
  133. targetType: [{ required: true, message: '请选择模板', trigger: 'change' }],
  134. sort: [
  135. { required: true, message: '请输入排序', trigger: 'blur' }
  136. ],
  137. targetContent: [{ required: true, message: '请输入项目Code', trigger: 'blur' }],
  138. status: [{ required: true, message: '请选择状态', trigger: 'change' }]
  139. }
  140. }
  141. },
  142. created() {
  143. this.$store.dispatch('dashboard/getRowItemList', {
  144. id: this.$route.query.id
  145. })
  146. },
  147. // eslint-disable-next-line vue/order-in-components
  148. computed: {
  149. ...mapGetters([
  150. 'getRowItemData'
  151. ])
  152. },
  153. methods: {
  154. newDate(date) {
  155. return new Date(date).toLocaleString()
  156. },
  157. name() {
  158. const id = this.$route.query.id
  159. let name = ''
  160. switch (id) {
  161. case '0':
  162. name = '知识付费'
  163. break
  164. case '1':
  165. name = '学前'
  166. break
  167. case '2':
  168. name = '小学'
  169. break
  170. case '3':
  171. name = '中学'
  172. break
  173. }
  174. return name
  175. },
  176. template(code) {
  177. let templateCode = ''
  178. switch (code) {
  179. case 'IMAGE_TEMPATE_5':
  180. templateCode = '689*174图片模板'
  181. break
  182. case 'TEXT_TEMPLATE':
  183. templateCode = '文字模板'
  184. break
  185. case 'IMAGE_TEMPATE_1':
  186. templateCode = '840*300图片模板'
  187. break
  188. case 'IMAGE_TEMPATE_2':
  189. templateCode = '548*300图片模板'
  190. break
  191. case 'IMAGE_TEMPATE_3':
  192. templateCode = '404*256图片模板'
  193. break
  194. case 'IMAGE_TEMPATE_4':
  195. templateCode = '256*360图片模板'
  196. break
  197. case 'SCHEDULE_TEMPATE_1':
  198. templateCode = '1414*172课程表模板'
  199. break
  200. case 'SCHEDULE_TEMPATE_2':
  201. templateCode = '326*174课程表模板'
  202. break
  203. case 'SCHEDULE_TEMPATE_3':
  204. templateCode = '1414*172课程表模板'
  205. break
  206. }
  207. return templateCode
  208. },
  209. targetType(type) {
  210. let target = ''
  211. switch (type) {
  212. case 'LIBRARY':
  213. target = '图书馆课程'
  214. break
  215. case 'PAY':
  216. target = '知识付费课程'
  217. break
  218. case 'TOPIC':
  219. target = '专题'
  220. break
  221. case 'SCHEDULE':
  222. target = '课程表'
  223. break
  224. case 'URL':
  225. target = 'URL'
  226. break
  227. }
  228. return target
  229. },
  230. handleEdit(index, row) {
  231. console.log(index, row)
  232. this.dialogFormVisible = true
  233. this.type = 'set'
  234. this.form = {
  235. 'id': '',
  236. 'rowId': '',
  237. 'content': '',
  238. 'icon': '',
  239. 'targetType': '',
  240. 'targetContent': '',
  241. 'sort': '',
  242. 'status': ''
  243. }
  244. this.setForm(row)
  245. },
  246. addList() {
  247. this.dialogFormVisible = true
  248. this.type = 'add'
  249. this.form = {
  250. 'rowId': this.$route.query.id,
  251. 'content': '',
  252. 'icon': '',
  253. 'targetType': '',
  254. 'targetContent': '',
  255. 'sort': '',
  256. 'status': ''
  257. }
  258. },
  259. handleUp(index, row) {
  260. console.log(index, row)
  261. this.setForm(row)
  262. this.form.status = row.status === 'NOT_ON_STOCK' ? 'HAS_ON_STOCK' : 'NOT_ON_STOCK'
  263. this.$store.dispatch('dashboard/setRowItemList', this.form).then(() => {
  264. this.$store.dispatch('dashboard/getRowItemList', {
  265. id: this.$route.query.id
  266. })
  267. })
  268. },
  269. handOk(formName) {
  270. this.$refs[formName].validate((valid) => {
  271. if (valid) {
  272. if (this.type === 'set') {
  273. console.log(this.form)
  274. this.$store.dispatch('dashboard/setRowItemList', this.form).then(() => {
  275. this.dialogFormVisible = false
  276. this.$store.dispatch('dashboard/getRowItemList', {
  277. id: this.$route.query.id
  278. })
  279. })
  280. } else {
  281. this.$store.dispatch('dashboard/addRowItemList', this.form).then(() => {
  282. this.dialogFormVisible = false
  283. this.$store.dispatch('dashboard/getRowItemList', {
  284. id: this.$route.query.id
  285. })
  286. })
  287. }
  288. } else {
  289. console.log('error submit!!')
  290. return false
  291. }
  292. })
  293. },
  294. setForm(data) {
  295. this.form = {
  296. 'id': data.id,
  297. 'rowId': data.rowId,
  298. 'content': data.content,
  299. 'icon': data.icon,
  300. 'targetType': data.targetType,
  301. 'targetContent': data.targetContent,
  302. 'sort': data.sort,
  303. 'status': data.status
  304. }
  305. }
  306. }
  307. }
  308. </script>
  309. <style lang="scss" scoped>
  310. .dashboard {
  311. &-container {
  312. margin: 30px;
  313. }
  314. &-text {
  315. font-size: 30px;
  316. line-height: 46px;
  317. }
  318. }
  319. .el-input {
  320. width: 280px;
  321. }
  322. .el-select>.el-input {
  323. width: 300px;
  324. }
  325. .el-pagination {
  326. text-align: center;
  327. margin-top: 20px;
  328. }
  329. .el-tag.el-tag--danger {
  330. float: right;
  331. }
  332. </style>