应无所住,而生其心
排名
1
文章
860
粉丝
112
评论
163
net core webapi post传递参数
庸人 : 确实坑哈,我也是下班好了好几次,发现后台传递对象是可以的,但...
百度编辑器自定义模板
庸人 : 我建议换个编辑器,因为现在百度富文本已经停止维护了,用tinymec...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术

elmentui 弹窗,自定义样式 修改里边默认样式,自定义header,自定义头部等。Vue自定义组件的使用。Vue模板。Vue弹窗实现反馈页面

6533人阅读 2020/6/9 10:19 总访问:5182827 评论:0 收藏:0 手机
分类: 前端

这样一个效果

主要分为三块:

  • 一块是:一个简单的可以拖动的右下角悬浮菜单组件封装,点击它弹出这个弹窗
  • 一块是:对于这个弹窗的自定义样式,主要是header和body和footer插槽的使用,也是封装的一个组件
  • 一块是:最下面关于图片上传的组件封装,还有就是图片预览的组件的使用

可以拖动的悬浮菜单部分代码如下:

是触发的第一个组件。部分代码如下,详细的可以参考下方连接

  1. <template>
  2. <div>
  3. <!-- 悬浮菜单开始 -->
  4. <div class="realTranslationInfos" v-drag>
  5. <div class="RealtranslationBox">
  6. <img draggable="false" @click="openFeedbackDialog()" src="@/assets/imgs/labroom/feedback.png" alt=""
  7. width="66px" height="66px">
  8. </div>
  9. </div>
  10. <!-- 悬浮菜单结束 -->
  11. <!-- 封装的弹窗组件 -->
  12. <FeedbackDialog ref="feedbackDialog" />
  13. </div>
  14. </template>
  15. <script>
  16. import FeedbackDialog from '@/pages/feedback/feedbackDialog.vue'
  17. export default {
  18. // 组件名字
  19. name: 'FeedBack',
  20. components: {
  21. FeedbackDialog
  22. },
  23. // 组件参数
  24. props: {
  25. id: {
  26. type: String,
  27. default: ''
  28. },
  29. index: {
  30. type: Number,
  31. default: 0
  32. },
  33. },
  34. data() {
  35. return {
  36. // 用来给自己封装的弹窗组件传递参数
  37. dialogVisible: false
  38. }
  39. },
  40. mounted() {
  41. },
  42. // 组件方法
  43. methods: {
  44. openFeedbackDialog() {
  45. //调用子组件的方法打开弹窗
  46. this.$refs.feedbackDialog.openFeedbackDialog();
  47. }
  48. }
  49. }
  50. </script>
  51. <style scoped="scoped" lang="scss">
  52. .realTranslationInfos {
  53. width: 66px;
  54. height: 66px;
  55. // background: red;
  56. position: fixed;
  57. // position: absolute;
  58. bottom: 56px;
  59. right: 20px;
  60. // bottom: 122px;
  61. // right: -30px;
  62. .translationContent {
  63. min-height: 100px;
  64. line-height: 23px;
  65. width: 338px;
  66. padding: 18px 74px 19px 19px;
  67. background: #004CB3;
  68. opacity: 0.80;
  69. border-radius: 12px;
  70. color: #fff;
  71. position: fixed;
  72. // position: absolute;
  73. right: 58px;
  74. bottom: 22px;
  75. z-index: 99999;
  76. }
  77. .RealtranslationBox {
  78. display: flex;
  79. align-items: center;
  80. position: absolute;
  81. right: 2px;
  82. bottom: 5px;
  83. z-index: 99999;
  84. img {
  85. cursor: pointer;
  86. }
  87. }
  88. }
  89. </style>

详细的使用可以参考:https://www.tnblog.net/aojiancc2/article/details/7829

这里打开子组件弹窗的方式是调用子组件的方法打开的弹窗

  1. openFeedbackDialog() {
  2. //调用子组件的方法打开弹窗
  3. this.$refs.feedbackDialog.openFeedbackDialog();
  4. }

vue3中父组件调用子组件方法有点不一样了,参考:https://www.tnblog.net/xiuxin/article/details/8153

第二块:关于弹窗的自定义样式

  1. <!-- 问题反馈使用的弹窗 -->
  2. <template>
  3. <div>
  4. <!-- 弹窗start -->
  5. <div class="dialogContent">
  6. <el-dialog :visible.sync="dialogVisible" :show-close="false" width="700px" height="800px"
  7. :before-close="handleClose">
  8. <div slot="title" class="dialog-footer">
  9. <div style="font-size:16px">
  10. 问题反馈
  11. </div>
  12. <div class="separateline">
  13. </div>
  14. </div>
  15. <div style="margin-top:-10px">
  16. <div style="display:flex">
  17. <div style="width:78px;color:#000">
  18. 问题类型:
  19. </div>
  20. <div>
  21. <el-radio v-model="radio" label="1">系统问题</el-radio>
  22. <el-radio v-model="radio" label="2">内容问题</el-radio>
  23. <el-radio v-model="radio" label="3">我要吐槽</el-radio>
  24. </div>
  25. </div>
  26. <div style="display:flex;margin-top: 30px;">
  27. <div style="width:78px;color:#000;">
  28. 描&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;述:
  29. </div>
  30. <div style="flex-grow: 1">
  31. <el-input type="textarea" v-model="describe" style="width:100%" :rows="7" placeholder="请输入内容">
  32. </el-input>
  33. </div>
  34. </div>
  35. <div style="display:flex;margin-top: 30px;">
  36. <div style="width:78px;color:#000">
  37. 问题截图:
  38. </div>
  39. <div style="flex-grow: 1">
  40. <!-- 引用图片上传的组件 -->
  41. <UpLoadImg />
  42. </div>
  43. </div>
  44. </div>
  45. <span slot="footer" class="dialog-footer">
  46. <el-button @click="dialogVisible = false" size="small">我在想想</el-button>
  47. <el-button type="primary" size="small" @click="dialogVisible = false">确定反馈</el-button>
  48. </span>
  49. </el-dialog>
  50. </div>
  51. <!-- 弹窗end -->
  52. </div>
  53. </template>
  54. <script>
  55. import UpLoadImg from '@/pages/feedback/upLoadImg.vue'
  56. export default {
  57. // 组件名字
  58. name: 'FeedbackDialog',
  59. components: {
  60. UpLoadImg
  61. },
  62. // 组件参数
  63. props: {
  64. index: {
  65. type: Number,
  66. default: 0
  67. },
  68. },
  69. data() {
  70. return {
  71. radio: "3",
  72. describe:"",
  73. dialogVisible: false
  74. }
  75. },
  76. mounted() {
  77. //alert("组件内部加载好了"+this.dialogVisibleParameter)
  78. this.initPic()
  79. },
  80. // 组件方法
  81. methods: {
  82. initPic() {
  83. },
  84. //模态框关闭前的事件
  85. handleClose(done) {
  86. },
  87. //打开弹窗
  88. openFeedbackDialog() {
  89. this.dialogVisible = true
  90. }
  91. }
  92. }
  93. </script>
  94. <style scoped="scoped" lang="scss">
  95. // 自定义的一根简单分割线
  96. .separateline {
  97. height: 1px;
  98. background: #eee;
  99. margin-left: -40px;
  100. margin-right: -40px;
  101. margin-top: 9px;
  102. }
  103. // 问题截图,传递图片的样式
  104. .form-content.panle {
  105. // padding: 20px;
  106. padding-bottom: 10px;
  107. // background-color: #f8f8f8;
  108. .img-boxs {
  109. display: flex;
  110. /* margin-right: 46px; */
  111. flex-wrap: wrap;
  112. .img-waper {
  113. margin-right: 10px;
  114. margin-bottom: 10px;
  115. position: relative;
  116. .remove-icon:hover {
  117. cursor: pointer;
  118. img {
  119. opacity: 0.6;
  120. }
  121. }
  122. .remove-icon {
  123. position: absolute;
  124. width: 14px;
  125. height: 14px;
  126. top: -8px;
  127. right: -5px;
  128. img {
  129. width: 100%;
  130. }
  131. }
  132. }
  133. }
  134. .add-btn:hover {
  135. cursor: pointer;
  136. opacity: 0.6;
  137. }
  138. .add-btn {
  139. width: 70px;
  140. height: 70px;
  141. border: solid 1px #DDDDDD;
  142. display: flex;
  143. align-items: center;
  144. flex-wrap: wrap;
  145. justify-content: space-around;
  146. .icon-waper {
  147. width: 18px;
  148. height: 21px;
  149. position: relative;
  150. .icon-x {
  151. width: 19px;
  152. height: 5px;
  153. background-color: #DDDDDD;
  154. position: absolute;
  155. top: 0;
  156. bottom: 0;
  157. margin: auto;
  158. }
  159. .icon-y {
  160. height: 21px;
  161. width: 5px;
  162. background-color: #DDDDDD;
  163. position: absolute;
  164. left: 0;
  165. right: 0;
  166. margin: auto;
  167. }
  168. }
  169. }
  170. }
  171. </style>
  172. <!-- 修改elementui里边对话框的默认样式
  173. 需要注意两点:
  174. 1:样式声明的时候不要加scoped,不然样式只在当前组件起作用,无法覆盖样式内容的样式
  175. 2:要修改默认弹窗里边的样式,加一个前缀,就可以做到只修改当前这个组件的了,不然可能会影响到其他地方的样式
  176. -->
  177. <style lang="scss">
  178. /* .dialogContent .el-dialog {
  179. background-color: #F6F8FC;
  180. }
  181. .dialogContent .el-dialog__header {
  182. padding: 20px 40px 10px 40px
  183. }
  184. .dialogContent .el-dialog__body {
  185. padding: 30px 40px;
  186. color: #606266;
  187. font-size: 14px;
  188. word-break: break-all;
  189. } */
  190. // 修改el-dialog里边的默认样式
  191. .dialogContent {
  192. .el-dialog {
  193. background-color: #F6F8FC;
  194. }
  195. .el-dialog__header {
  196. padding: 20px 40px 10px 40px
  197. }
  198. .el-dialog__body {
  199. padding: 30px 40px;
  200. color: #606266;
  201. font-size: 14px;
  202. word-break: break-all;
  203. }
  204. .el-dialog__footer {
  205. padding: 0px 40px 30px 40px
  206. }
  207. // 修改默认按钮的padding也就是跳转按钮的宽度
  208. .el-button--small,
  209. .el-button--small.is-round {
  210. padding: 9px 16px;
  211. }
  212. // 修改默认按钮的圆角为直角
  213. .el-button--mini,
  214. .el-button--small {
  215. border-radius: 0px;
  216. }
  217. }
  218. </style>

第三块:关于图片上传的组件

  1. <!-- 问题反馈使用的弹窗 -->
  2. <template>
  3. <div>
  4. <!-- 图片上传start -->
  5. <div class="form-content panle">
  6. <div class="img-boxs">
  7. <div v-for="(item,i) in taskResoult.imgJson" :key="i+'img'" class="img-waper" @click="onPreviewImg(i)">
  8. <img :src="'/oss/api/ImageViewer/'+item.id+'.jpg?percent=0.6&quality=80&od=true'" width="79px"
  9. height="79px">
  10. <div class="remove-icon" @click="rmImgs(i)">
  11. <img src="/asserts/img/error.png">
  12. </div>
  13. </div>
  14. <div v-if="taskResoult.imgJson.length<9" class="img-waper">
  15. <div class="add-btn" @click="addImgClick">
  16. <input ref="inputImgFile" type="file" @change="uploadimg" style="display: none;"
  17. accept="image/*">
  18. <div class="icon-waper">
  19. <div class="icon-x" />
  20. <div class="icon-y" />
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <!-- 图片上传end -->
  27. <!-- 图片预览start -->
  28. <el-image-viewer v-if="showViewer" :z-index="20000" :initial-index="initialIndex" :append-to-body="true"
  29. :on-close="closeViewer" :mask-closable="false" :url-list="taskResoult.imgJson.map(a=>a.fileUrl)" />
  30. <!-- 图片预览end -->
  31. </div>
  32. </template>
  33. <script>
  34. import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
  35. export default {
  36. // 组件名字
  37. name: 'UpLoadImg',
  38. components: {
  39. ElImageViewer
  40. },
  41. // 组件参数
  42. props: {
  43. index: {
  44. type: Number,
  45. default: 0
  46. },
  47. },
  48. data() {
  49. return {
  50. showViewer: false,
  51. initialIndex: 0,
  52. taskResoult: {
  53. 'uploadFileID': '',
  54. stuImgs: '',
  55. imgJson: [],
  56. 'uploadFileInfo': '',
  57. uploadFileInfoJson: {},
  58. 'remarks': null
  59. }
  60. }
  61. },
  62. mounted() {
  63. this.initPic()
  64. },
  65. // 组件方法
  66. methods: {
  67. initPic() {
  68. },
  69. //点击添加图片,直接触发文件选择框的事件即可
  70. addImgClick() {
  71. this.$refs.inputImgFile.click()
  72. },
  73. //打开图片预览
  74. onPreviewImg(i) {
  75. //设置预览图片的索引
  76. this.initialIndex = i
  77. this.showViewer = true
  78. },
  79. // 关闭图片预览
  80. closeViewer() {
  81. this.showViewer = false
  82. },
  83. rmImgs(i) {
  84. this.taskResoult.imgJson.splice(i, 1)
  85. // console.log(self.taskResoult)
  86. this.$forceUpdate()
  87. },
  88. //上传图片逻辑。文件选择框的change事件触发
  89. uploadimg(e) {
  90. // 日精进上传图片
  91. const imgFileExtensionArry = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff']
  92. const file = e.target.files[0]
  93. const fileExt = file.name.substr(file.name.lastIndexOf('.') + 1)
  94. if (imgFileExtensionArry.indexOf(fileExt.toLowerCase()) === -1) {
  95. this.$message.warning('仅允许提交图片文件!')
  96. return
  97. }
  98. const formData = new FormData()
  99. formData.append('bucketName', 'labroom')
  100. formData.append('filePath', 'labresult')
  101. formData.append('FileType', 1)
  102. formData.append('file', file)
  103. if (this.taskResoult.stuImgs && this.taskResoult.imgJson.length === 9) {
  104. this.$message.error('不允许超过9张图片')
  105. return
  106. }
  107. const self = this
  108. self.$service.api.UpLoadFormFile(formData).then(res => {
  109. const imgInfo = {
  110. id: res.data.id,
  111. fileName: res.data.title,
  112. fileUrl: '/oss/api/ImageViewer/' + res.data.id + '.jpg'
  113. }
  114. self.taskResoult.imgJson.push(imgInfo)
  115. console.log(self.taskResoult)
  116. self.$forceUpdate()
  117. })
  118. }
  119. }
  120. }
  121. </script>
  122. <style scoped="scoped" lang="scss">
  123. // 问题截图,传递图片的样式
  124. .form-content.panle {
  125. // padding: 20px;
  126. padding-bottom: 10px;
  127. // background-color: #f8f8f8;
  128. .img-boxs {
  129. display: flex;
  130. /* margin-right: 46px; */
  131. flex-wrap: wrap;
  132. .img-waper {
  133. margin-right: 10px;
  134. margin-bottom: 10px;
  135. position: relative;
  136. .remove-icon:hover {
  137. cursor: pointer;
  138. img {
  139. opacity: 0.6;
  140. }
  141. }
  142. .remove-icon {
  143. position: absolute;
  144. width: 14px;
  145. height: 14px;
  146. top: -8px;
  147. right: -5px;
  148. img {
  149. width: 100%;
  150. }
  151. }
  152. }
  153. }
  154. .add-btn:hover {
  155. cursor: pointer;
  156. opacity: 0.6;
  157. }
  158. .add-btn {
  159. width: 79px;
  160. height: 79px;
  161. border: solid 1px #DDDDDD;
  162. display: flex;
  163. align-items: center;
  164. flex-wrap: wrap;
  165. justify-content: space-around;
  166. .icon-waper {
  167. width: 18px;
  168. height: 21px;
  169. position: relative;
  170. .icon-x {
  171. width: 19px;
  172. height: 5px;
  173. background-color: #DDDDDD;
  174. position: absolute;
  175. top: 0;
  176. bottom: 0;
  177. margin: auto;
  178. }
  179. .icon-y {
  180. height: 21px;
  181. width: 5px;
  182. background-color: #DDDDDD;
  183. position: absolute;
  184. left: 0;
  185. right: 0;
  186. margin: auto;
  187. }
  188. }
  189. }
  190. }
  191. </style>

详细的图片预览的组件的使用可以参考:
https://www.tnblog.net/aojiancc2/article/details/7830


欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)

评价

EasyUI弹窗批量修改combogrid下拉框的值

JS方法//点击弹出批量修改框 UpdateLot:function(){ varrow=$(&quot;#dg&quot;).datagrid(&quot;getChecked&quot;); if(...

layer弹窗+ef引入独立页面进行操作

使用layer弹窗进行操作的时候我们可以使用type=2,来把一个独立的页面指向content内容例如我们有一个表格,点击添加后,我...

百度编辑器在layer弹窗中加载问题

因为加载到layer后百度编辑器要从新渲染一遍,所以如果使用setContent(Content)设置的内容在加载到layer弹窗中是显示不出来...

表格在layer弹窗中居中表格居中

其实很简单直接给table设置一个margin:top auto就可以了layer:layer.open({ type:1, title:&quot;更新&quot;, area:[&qu...

layui 弹窗遮罩层把弹窗挡住问题

代码:layer.open({ type:1, area:[&quot;300px&quot;,&quot;300px&quot;], content:$(&quot;#addvieww&quot;) });分析...

layer弹窗i获取id

直接贴代码,这个实在yes回调函数里边执行的,通过index去找 yes: function (index) { var nowLayer = $(&quot;#layui-lay...

layer弹窗放jquery对象被遮住了

html &lt;div id=&quot;showcontent&quot; style=&quot;display: none&quot;&gt; hello layer &lt;/div&gt; js: l...

XAF获取PopupWindowShowAction弹窗窗体的字段数据

在Execute点击事件里面获取数据获取窗体视图数据DetailView view= e.PopupWindowView as DetailView;将窗体视图数据转换为...

XAF弹窗按钮弹出自定义窗体

加载CustomizePopupWindowParams事件并创建窗体弹出private void popupWindowShowAction1_CustomizePopupWindowParams(obje...

layer弹窗

//先引入layer的js layer.open({ //属性 type:1, //标题 title:&quot;内容修改&quot;, //content(正文)可传obj,...

layer弹窗 获取frames的值

通过window.frames[&quot;name&quot;]可以调用layer弹页窗指向页面的方法//例如目标页面存在一个方法 varupdate=function(...

uni-app的常见弹窗

前 言uni-app uni-app常见的几种提示框uni-app常见提示框:成功提示: 加载框:文字:弹窗:模态弹窗和非模态弹窗 模态弹...

elementui对话框Dialog使用配合表单使用。Vue-element-ui 弹窗弹出层

Dialog 弹出一个对话框,适合需要页面元素更多的场景。需要设置visible属性,它接收Boolean,当为true时显示 Dialog。Dialo...

uni-app弹出层弹窗

最简单的弹出一句话:需要什么东西在内容里边加就行了 &lt;template&gt; &lt;view&gt; &lt;uni-popup ref=&...

uni-app弹窗小程序弹出层。自定义组件弹窗解决滚动穿透

官方文档:https://uniapp.dcloud.net.cn/component/uniui/uni-popup.html [TOC]最简单的弹出一句话:需要什么东西在内容...