add.vue 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="subPage">
  3. <form class="mainForm">
  4. <ul>
  5. <li class="flex-h">
  6. <span>跳转类型:</span>
  7. <div class="flex-item">
  8. <div style="width:50%" class="radio">
  9. <el-radio v-model="postData.ForwardType" label='1' >链接</el-radio>
  10. <el-radio v-model="postData.ForwardType" label='0' >课程</el-radio>
  11. </div>
  12. </div>
  13. </li>
  14. <li class="flex-h">
  15. <span>链接:</span>
  16. <div class="flex-item">
  17. <div style="width:50%">
  18. <el-input
  19. placeholder="请输入链接"
  20. v-model="postData.ForwardUrl"
  21. clearable>
  22. </el-input>
  23. </div>
  24. </div>
  25. </li>
  26. <li class="flex-h">
  27. <span>是否发布:</span>
  28. <div class="flex-item">
  29. <div style="width:50%" class="radio">
  30. <el-radio v-model="postData.Status" label='1' >是</el-radio>
  31. <el-radio v-model="postData.Status" label='0' >否</el-radio>
  32. </div>
  33. </div>
  34. </li>
  35. <li class="flex-h">
  36. <span>图片位置:</span>
  37. <div class="flex-item">
  38. <div style="width:50%">
  39. <el-select style="width:100%" v-model="postData.LocationIds" multiple placeholder="请选择">
  40. <el-option
  41. v-for="item in positionList"
  42. :key="item.LocationId"
  43. :label="item.LocationName"
  44. :value="item.LocationId">
  45. </el-option>
  46. </el-select>
  47. </div>
  48. </div>
  49. </li>
  50. <li class="flex-h">
  51. <span>标题:</span>
  52. <div class="flex-item">
  53. <div style="width:50%">
  54. <el-input
  55. placeholder="请输入标题"
  56. v-model="postData.Title"
  57. clearable>
  58. </el-input>
  59. </div>
  60. </div>
  61. </li>
  62. <li class="flex-h">
  63. <span>图片:</span>
  64. <div class="flex-item">
  65. <!-- <el-upload
  66. :action="$api.file.image.url"
  67. :limit='limit'
  68. list-type="picture-card"
  69. :file-list='imgsArr'
  70. :on-success="handlePictureCardPreview"
  71. :on-remove="handleRemove"
  72. :on-exceed="exceed">
  73. <i class="el-icon-plus"></i>
  74. </el-upload>
  75. <el-dialog :visible.sync="dialogVisible">
  76. <img width="100%" :src="imgs" alt="">
  77. </el-dialog> -->
  78. <!-- 单选 -->
  79. <el-upload
  80. class="avatar-uploader"
  81. :action='$api.file.image.url'
  82. :show-file-list="false"
  83. :on-success="handleAvatarSuccess">
  84. <img v-if="postData.ImageUrl" :src="postData.ImageUrl" class="avatar">
  85. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  86. </el-upload>
  87. </div>
  88. </li>
  89. <li style="text-align:center">
  90. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  91. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  92. </li>
  93. </ul>
  94. </form>
  95. </div>
  96. </template>
  97. <script>
  98. import { mapState, mapActions, createNamespacedHelpers } from 'vuex'
  99. const { mapActions: mapCmsActions } = createNamespacedHelpers('cms')
  100. export default {
  101. name: '',
  102. data () {
  103. return {
  104. postData: {
  105. ForwardType: '1',
  106. ForwardUrl: '',
  107. ForwardResourceId: '',
  108. Status: '1',
  109. LocationIds: [],
  110. ImageUrl: '',
  111. Title: '',
  112. OrgId: '',
  113. CaseId: ''
  114. },
  115. dialogVisible: false,
  116. imgs: '',
  117. imgsArr: [],
  118. limit: 1
  119. }
  120. },
  121. components: {},
  122. created () {
  123. this.updateSystemInfo().then(() => {
  124. this.postData.OrgId = this.OrgId
  125. this.postData.CaseId = this.CaseId
  126. })
  127. },
  128. computed: {
  129. ...mapState({
  130. positionList: x => x.cms.location,
  131. OrgId: x => x.app.user.OrgId,
  132. CaseId: x => x.app.cases.default,
  133. })
  134. },
  135. methods: {
  136. ...mapActions(['updateSystemInfo']),
  137. ...mapCmsActions(['updateLocationInfo']),
  138. submit () {
  139. if (this.postData.ForwardType === '1') {
  140. if (this.postData.ForwardUrl === '') {
  141. this.$message({
  142. message: '链接地址不能为空',
  143. type: 'error',
  144. })
  145. return false
  146. } else {
  147. var reg = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/ // eslint-disable-line
  148. if (!reg.test(this.postData.ForwardUrl)) {
  149. this.$message({
  150. message: '链接地址格式不正确',
  151. type: 'error',
  152. })
  153. return false
  154. }
  155. }
  156. }
  157. this.postData.ForwardType === '1' ? this.postData.ForwardType = 'url' : this.postData.ForwardType = 'course'
  158. this.postData.locationids = this.postData.LocationIds.join(',')
  159. // this.postData.ImageUrl = ''
  160. // for (let i = 0; i < this.imgsArr.length; i++) {
  161. // this.postData.ImageUrl += this.imgsArr[i].response.result.url + ','
  162. // }
  163. // if (this.postData.ImageUrl) {
  164. // this.postData.ImageUrl = this.postData.ImageUrl.substr(0, this.postData.ImageUrl.length - 1)
  165. // }
  166. this.$ajax(this.$api.cms.addNews.url, {
  167. method: this.$api.cms.addNews.method,
  168. data: this.postData
  169. }).then(res => {
  170. this.$message({
  171. message: '添加成功',
  172. type: 'success',
  173. duration: 1000
  174. })
  175. setTimeout(() => {
  176. this.$router.push({ name: 'newsManager' })
  177. }, 1000)
  178. }).catch(msg => {
  179. })
  180. },
  181. cancel () {
  182. this.$router.go(-1)
  183. },
  184. // handlePictureCardPreview (res, file, fileList) {
  185. // this.imgs = res.result.url
  186. // this.dialogVisible = false
  187. // this.imgsArr = fileList
  188. // },
  189. // handleRemove (file, fileList) {
  190. // this.imgsArr = fileList
  191. // },
  192. // exceed () {
  193. // this.$message({
  194. // message: '超过可传的图片上限',
  195. // type: 'info',
  196. // duration: 1000
  197. // })
  198. // }
  199. handleAvatarSuccess (res, file) {
  200. this.postData.ImageUrl = res.result.url
  201. },
  202. }
  203. }
  204. </script>
  205. <!-- Add "scoped" attribute to limit CSS to this component only -->
  206. <style lang="scss" scoped>
  207. </style>