tab2Add.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <div class="tab2Add">
  3. <div class="insideTop">
  4. 学院领导管理 > 新增领导信息
  5. <div class="add">
  6. <el-button type="primary" @click="goBack">返 回</el-button>
  7. </div>
  8. </div>
  9. <div class="obstruct"></div>
  10. <!-- 主要内容 -->
  11. <div class="conten">
  12. <div class="con_top">基本信息</div>
  13. <!-- 表单 -->
  14. <el-form
  15. :model="ruleForm"
  16. :rules="rules"
  17. ref="ruleForm"
  18. label-width="120px"
  19. class="demo-ruleForm"
  20. >
  21. <el-form-item label="姓名:" prop="name">
  22. <el-input
  23. v-model="ruleForm.name"
  24. maxlength="25"
  25. show-word-limit
  26. style="width: 500px"
  27. ></el-input>
  28. </el-form-item>
  29. <el-form-item label="性别:" prop="sex">
  30. <el-radio v-model="ruleForm.sex" label="1">男</el-radio>
  31. <el-radio v-model="ruleForm.sex" label="0">女</el-radio>
  32. </el-form-item>
  33. <el-form-item label="政治面貌:" prop="face">
  34. <el-select
  35. v-model="ruleForm.face"
  36. placeholder="请选择"
  37. style="width: 500px"
  38. >
  39. <el-option label="中共党员" value="中共党员"></el-option>
  40. <el-option label="中共预备党员" value="中共预备党员"></el-option>
  41. <el-option label="共青团员" value="共青团员"></el-option>
  42. <el-option label="民革党员" value="民革党员"></el-option>
  43. <el-option label="民盟盟员" value="民盟盟员"></el-option>
  44. <el-option label="民建会员" value="民建会员"></el-option>
  45. <el-option label="民进会员" value="民进会员"></el-option>
  46. <el-option label="农工党党员" value="农工党党员"></el-option>
  47. <el-option label="致公党党员" value="致公党党员"></el-option>
  48. <el-option label="九三学社社员" value="九三学社社员"></el-option>
  49. <el-option label="台盟盟员" value="台盟盟员"></el-option>
  50. <el-option label="无党派人士" value="无党派人士"></el-option>
  51. <el-option label="群众" value="群众"></el-option>
  52. </el-select>
  53. </el-form-item>
  54. <el-form-item label="任期职位:" prop="position">
  55. <el-input
  56. v-model="ruleForm.position"
  57. maxlength="50"
  58. show-word-limit
  59. style="width: 500px"
  60. ></el-input>
  61. </el-form-item>
  62. <el-form-item label="任期:">
  63. <i class="biaoshi biaoshi1"></i>
  64. <el-date-picker
  65. style="width: 500px"
  66. v-model="time"
  67. type="daterange"
  68. range-separator="-"
  69. start-placeholder="开始时间"
  70. end-placeholder="结束时间"
  71. >
  72. </el-date-picker>
  73. </el-form-item>
  74. <!-- 图片和附件 -->
  75. <el-form-item label="领导照片">
  76. <i class="biaoshi biaoshi2"></i>
  77. <el-upload
  78. class="avatar-uploader"
  79. :action="baseURL + '/cms/security/video/upload/img'"
  80. :headers="{
  81. token,
  82. }"
  83. :show-file-list="false"
  84. :before-upload="beforethumbUpload"
  85. :on-success="upload_thumb_success"
  86. >
  87. <div v-if="ruleForm.thumb" class="imgdiv">
  88. <img
  89. style="width: 100%; height: 100%"
  90. :src="baseURL + ruleForm.thumb"
  91. />
  92. <i
  93. class="el-icon-circle-close"
  94. @click.stop="ruleForm.thumb = ''"
  95. ></i>
  96. </div>
  97. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  98. </el-upload>
  99. <p class="upHint">
  100. 格式要求:支持png、jpg、gif和jpeg的图片格式;最大支持20M。
  101. </p>
  102. </el-form-item>
  103. </el-form>
  104. <!-- 富文本 -->
  105. <div class="con_top">领导简介</div>
  106. <div id="div1" style="z-index: 1"></div>
  107. <!-- 底部按钮 -->
  108. <div class="con_btn">
  109. <el-button type="primary">保 存</el-button>
  110. </div>
  111. </div>
  112. </div>
  113. </template>
  114. <script>
  115. import E from 'wangeditor'
  116. export default {
  117. name: 'tab2Add',
  118. components: {},
  119. data () {
  120. // 这里存放数据
  121. return {
  122. time: '',
  123. // 服务器前缀地址
  124. baseURL: '',
  125. token: '',
  126. ruleForm: {
  127. name: '',
  128. sex: '1',
  129. face: '',
  130. position: '',
  131. startTime: '',
  132. endTime: '',
  133. thumb: ''
  134. },
  135. rules: {
  136. name: [{ required: true, message: '不能为空', trigger: 'blur' }],
  137. sex: [{ required: true, message: '不能为空', trigger: 'blur' }],
  138. face: [{ required: true, message: '不能为空', trigger: 'change' }],
  139. position: [{ required: true, message: '不能为空', trigger: 'change' }]
  140. }
  141. }
  142. },
  143. // 监听属性 类似于data概念
  144. computed: {},
  145. // 监控data中的数据变化
  146. watch: {
  147. time (val) {
  148. this.handleSelect(val)
  149. }
  150. },
  151. // 方法集合
  152. methods: {
  153. // 上传图片
  154. beforethumbUpload (file) {
  155. // console.log(998, file)
  156. // 限制图片大小和格式
  157. const sizeOk = file.size / 1024 / 1024 < 5
  158. const typeOk =
  159. file.type === 'image/png' ||
  160. file.type === 'image/jpeg' ||
  161. file.type === 'image/gif'
  162. return new Promise((resolve, reject) => {
  163. if (!typeOk) {
  164. this.$message.error('照片格式有误!')
  165. reject(file)
  166. } else if (!sizeOk) {
  167. this.$message.error('照片大小超过5M!')
  168. reject(file)
  169. } else if (file.name.length > 32) {
  170. this.$message.error('照片名字不能超过32个字!')
  171. reject(file)
  172. } else {
  173. this.$message.success('上传成功')
  174. resolve(file)
  175. }
  176. })
  177. },
  178. upload_thumb_success (data) {
  179. // console.log('图片上传成功', data.data.urlPath)
  180. this.ruleForm.thumb = data.data.urlPath
  181. },
  182. // 点击返回
  183. goBack () {
  184. this.$confirm('点击返回后,编辑的信息将无法保存,是否继续?', '提示', {
  185. confirmButtonText: '确定',
  186. cancelButtonText: '取消',
  187. type: 'warning'
  188. })
  189. .then(async () => {
  190. this.$router.push('/layout/tab2')
  191. })
  192. .catch(() => {
  193. this.$message.info('已取消')
  194. })
  195. },
  196. // 时间处理----------------
  197. handleSelect (e) {
  198. const date = []
  199. for (const i in e) {
  200. date.push(this.gettime(e[i]))
  201. }
  202. this.ruleForm.startTime = date[0]
  203. if (date[1]) {
  204. this.ruleForm.endTime = date[1].replace('00:00:00', '23:59:59')
  205. }
  206. if (e === null) this.ruleForm.endTime = ''
  207. },
  208. gettime (data) {
  209. const value =
  210. data.getFullYear() +
  211. '-' +
  212. this.checkTime(data.getMonth() + 1) +
  213. '-' +
  214. this.checkTime(data.getDate()) +
  215. ' ' +
  216. this.checkTime(data.getHours()) +
  217. ':' +
  218. this.checkTime(data.getMinutes()) +
  219. ':' +
  220. this.checkTime(data.getSeconds())
  221. return value
  222. },
  223. checkTime (i) {
  224. if (i < 10) {
  225. i = '0' + i
  226. }
  227. return i
  228. }
  229. },
  230. // 生命周期 - 创建完成(可以访问当前this实例)
  231. created () {},
  232. // 生命周期 - 挂载完成(可以访问DOM元素)
  233. mounted () {
  234. // 初始化富文本
  235. // 富文本
  236. this.editor = new E('#div1')
  237. // 配置字体
  238. this.editor.config.fontNames = [
  239. '黑体',
  240. '仿宋',
  241. '楷体',
  242. '标楷体',
  243. '华文仿宋',
  244. '华文楷体',
  245. '宋体',
  246. '微软雅黑',
  247. 'Arial',
  248. 'Tahoma',
  249. 'Verdana',
  250. 'Times New Roman'
  251. ]
  252. this.editor.config.uploadImgShowBase64 = true // 图片地址
  253. this.editor.config.showLinkVideo = false
  254. this.editor.create()
  255. this.editor.txt.html('66666666666666666')
  256. },
  257. beforeCreate () {}, // 生命周期 - 创建之前
  258. beforeMount () {}, // 生命周期 - 挂载之前
  259. beforeUpdate () {}, // 生命周期 - 更新之前
  260. updated () {}, // 生命周期 - 更新之后
  261. beforeDestroy () {}, // 生命周期 - 销毁之前
  262. destroyed () {}, // 生命周期 - 销毁完成
  263. activated () {} // 如果页面有keep-alive缓存功能,这个函数会触发
  264. }
  265. </script>
  266. <style lang='less' scoped>
  267. .tab2Add {
  268. height: 100%;
  269. .conten {
  270. padding-bottom: 10px;
  271. overflow-y: auto;
  272. height: calc(100% - 32px);
  273. .con_top {
  274. margin-bottom: 12px;
  275. height: 40px;
  276. line-height: 40px;
  277. padding-left: 20px;
  278. background-color: #fbfbfb;
  279. }
  280. .biaoshi1::before {
  281. left: -64px;
  282. top: -10px;
  283. }
  284. .biaoshi2::before {
  285. left: -78px;
  286. }
  287. /deep/.el-icon-plus {
  288. border: 1px dashed #ccc;
  289. }
  290. .avatar-uploader .el-upload {
  291. border-radius: 6px;
  292. cursor: pointer;
  293. position: relative;
  294. overflow: hidden;
  295. }
  296. .avatar-uploader .el-upload:hover {
  297. border-color: #3e5eb3;
  298. }
  299. .avatar-uploader-icon {
  300. font-size: 28px;
  301. color: #8c939d;
  302. width: 178px;
  303. height: 178px;
  304. line-height: 178px;
  305. text-align: center;
  306. }
  307. #div1{
  308. width: 85%;
  309. margin: 0 auto;
  310. }
  311. .con_btn {
  312. width: 80px;
  313. margin: 15px auto 0;
  314. }
  315. }
  316. }
  317. </style>