<%@ taglib prefix="emp" uri="http://www...._.net vue+ele ui 项目demo">
当前位置:   article > 正文

VUE+ELEMENT UI学习demo_.net vue+ele ui 项目demo

.net vue+ele ui 项目demo

 这几天,看了下vue+element ui的一些知识,现在将其写成一个demo,页面下过如下

代码如下:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
  2. <%@ taglib prefix="emp" uri="http://www.montnets.com/emp/i18n/tags/simple" %>
  3. <%@include file="/common/common.jsp" %>
  4. <%
  5. String iPath = request.getRequestURI().substring(0, request.getRequestURI().lastIndexOf("/"));
  6. String inheritPath = iPath.substring(0, iPath.lastIndexOf("/"));
  7. String commonPath = inheritPath.substring(0, inheritPath.lastIndexOf("/"));
  8. String skinPath = session.getAttribute("stlyeSkin") == null ? "default" : (String) session.getAttribute("stlyeSkin");
  9. String version = skinPath.contains("frame3.0") ? "v3" : skinPath.contains("frame4.0") ? "v4" : "v2";
  10. int index = skinPath.lastIndexOf("/");
  11. String skin = version + "-" + skinPath.substring(index + 1);
  12. %>
  13. <!doctype html>
  14. <style>
  15. .top_btn {
  16. margin-bottom: 40px;
  17. }
  18. .top_left_btn {
  19. margin-left: 5px;
  20. float: left;
  21. display: block;
  22. margin-bottom: 10px;
  23. }
  24. .top_right_btn {
  25. margin-right: 5px;
  26. float: right;
  27. display: block;
  28. margin-bottom: 10px;
  29. }
  30. .bottom {
  31. margin-top: 25px;
  32. float: right;
  33. }
  34. </style>
  35. <html lang="en">
  36. <head>
  37. <title>签约信息查询vue练习
  38. </title>
  39. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  40. <link href="<%=commonPath%>/common/css/frame.css?V=<%=StaticValue.getJspImpVersion() %>" rel="stylesheet"
  41. type="text/css"/>
  42. <link href="<%=skinPath %>/frame.css?V=<%=StaticValue.getJspImpVersion() %>" rel="stylesheet" type="text/css"/>
  43. <link href="<%=commonPath%>/common/css/vue/index.css?V=<%=StaticValue.getJspImpVersion() %>" rel="stylesheet"
  44. type="text/css"/>
  45. <link href="<%=commonPath%>/common/css/vue/index<%="-" + skin%>.css?V=<%=StaticValue.getJspImpVersion() %>"
  46. rel="stylesheet"
  47. type="text/css"/>
  48. <link href="<%=commonPath%>/common/css/vue/iview.css?V=<%=StaticValue.getJspImpVersion() %>" rel="stylesheet"
  49. type="text/css"/>
  50. <title>Title</title>
  51. </head>
  52. <body>
  53. <div id="container" class="container" >
  54. <%-- container与js中el属性对应的值保持一致--%>
  55. <span v-html="position"></span>
  56. <%-- v-html表示要展示的html,position为后台传输过来的值,需要在js中定义--%>
  57. <div id="rContent" class="rContent"
  58. v-if="access"
  59. style="margin-left:1.5rem;width: 95%">
  60.  <%-- v-if表示只有当满足条件时,才展示div中的东西,access同样为js中定义的属性,可以由后台传值--%>
  61. <div class="top_btn">
  62. <div class="top_left_btn">
  63. <el-button type="primary" size="mini" @click="add">新增
  64. </el-button>
  65. <%--@为v-on标签的缩写,表示给当前页面上的事件进行绑定,add为定义的方法 --%>
  66. </div>
  67. <div class="top_right_btn">
  68. <el-switch
  69. v-model="isSearch"
  70. active-color="#13ce66"
  71. inactive-color="#ff4949"
  72. active-text="显示搜索"
  73. inactive-text="隐藏搜索">
  74. </el-switch>
  75. <%--v-model实现属性值绑定,isSearch为js中定义的值,可以由后台传输--%>
  76. </div>
  77. </div>
  78. <el-card class="box-card" style="margin-bottom: 0.8rem; width: 100%" v-if="isSearch" shadow="hover">
  79. <el-form :inline="true" label-width="90px"
  80. class="mmsTplForm" style="width: 1000px; margin-left: 2%;padding: 14px 0 5px 0 ; float: left"
  81. size="mini"
  82. label-position="left">
  83. <el-form-item label="账号:">
  84. <el-input v-model="criteria.acctNo" clearable placeholder="账号" style="width: 195px"/>
  85. </el-form-item>
  86. <el-form-item label="手机号码:">
  87. <el-input v-model="criteria.phoneNo" clearable placeholder="手机号码" style="width: 195px"/>
  88. </el-form-item>
  89.  <%--criteria为后台定义的查询对象,acctNo和phoNo查询对象的属性--%>
  90. </el-form>
  91. <el-container>
  92. <el-header style="padding: 14px 0 5px 0" height="70px">
  93. <el-button style="float: left;" type="primary" @click="getQuery" size="mini"
  94. icon="el-icon-search">查询
  95. </el-button>
  96. </el-header>
  97. </el-container>
  98. </el-card>
  99. <!--------------------------------------------- 表格代码 --------------------------------------------->
  100. <el-card class="box-card" shadow="hover">
  101. <el-table
  102. size="mini"
  103. :empty-text="emptyText"
  104. :data="tableData"
  105. v-loading="loading"
  106. style="width: 100%;">
  107.   <%--:data等价于V-bind data,v-bind简写为:,实现属性值绑定,emptyText,tableData,loding都为js中定义的属性值--%>
  108. <el-table-column
  109. align="center"
  110. prop="cucuno"
  111. label="客户号">
  112. </el-table-column>
  113. <el-table-column
  114. align="center"
  115. prop="cutlno"
  116. label="电话号码">
  117. </el-table-column>
  118. <el-table-column
  119. align="center"
  120. prop="cuopnt"
  121. label="开机构代号">
  122. </el-table-column>
  123.   <%--prop为element ui中实现表单属性绑定的属性,cucuno,cutlno,cuopnt为后台定义前端页面展示Vo类的属性值--%>
  124. <el-table-column
  125. align="center"
  126. width="350"
  127. label="操作">
  128. <template slot-scope="scope123" v-if="scope123.row.id != 1 && scope123.row.id != 2 && scope123.row.id != 3">
  129. <%--scope123为自己在jsp中随意定义的值--%>
  130.   <el-button type="success" size="small" @click="edit(scope123.row)">编辑</el-button>
  131. <el-popover
  132. :ref="scope123.row.id"
  133. placement="top"
  134. width="180">
  135. <p>确定删除本条数据吗?</p>
  136. <div style="text-align: right; margin: 0">
  137. <el-button size="mini" type="text" @click="$refs[scope123.row.id].doClose()">取消
  138. </el-button>
  139.   <%--doClose()方法为vue中原生方法--%>
  140. <el-button :loading="delLoading" type="primary" size="mini"
  141. @click="subDelete(scope123.row.id)">确定
  142. </el-button>
  143. </div>
  144. <el-button slot="reference" type="danger" size="mini">删除</el-button>
  145. </el-popover>
  146. </template>
  147. </el-table-column>
  148. </el-table>
  149. </el-card>
  150. <!-- 新增编辑弹出框-->
  151. <el-dialog top="150px" :close-on-click-modal="false" :title="isAdd ? '新增' : '编辑'" :visible.sync="isShow" width="500px" :show-close="false">
  152. <%--isAdd,isShow为js中定义属性值,用来判断from表单的title是新增还是编辑,表单是否展示--%>
  153.   <el-form ref="testForm" :inline="true" :model="testForm" :rules="rules" size="small" label-width="150px">
  154. <%--rules为js中自定义的表单校验规则,testForm为js中自定义的表单属性--%>
  155.   <el-form-item label="客户号:">
  156. <el-input v-model="testForm.cucuno" placeholder="输入客户号" oninput="value=value.replace(/[^a-zA-Z0-9]/ig,'')"/>
  157. </el-form-item>
  158.   <%--v-model = "testForm.cucuno 表示绑定testForm表单中的cucuno属性"--%>
  159. <el-form-item label="电话号码:" >
  160. <el-input v-model="testForm.cutlno" placeholder="输入电话号码" oninput="value=value.replace(/[^\d]/g, '')"/>
  161. </el-form-item>
  162. <el-form-item label="开户机构代码:">
  163. <el-input v-model="testForm.cuopnt" placeholder="输入开户机代号" oninput="value=value.replace(/[^a-zA-Z0-9]/ig,'')"/>
  164. </el-form-item>
  165. <el-form-item label="备注:">
  166. <el-input v-model="testForm.remark" placeholder="请输入中文备注" onkeyup="value=value.replace(/[^\u4e00-\u9fa5]/g,'')"/>
  167. </el-form-item>
  168. </el-form>
  169. <div slot="footer" class="dialog-footer">
  170. <el-button type="text" @click="cancel">取消</el-button>
  171. <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
  172. </div>
  173. </el-dialog>
  174.   <%--分页--%>
  175. <div class="bottom">
  176. <el-pagination
  177. @size-change="handlePageSize"
  178. @current-change="handlePage"
  179. :current-page.sync="pageInfo.pageIndex"
  180. :page-sizes="pageInfo.pageSizeOpts"
  181. :page-size="pageInfo.pageSize"
  182. layout="total, sizes, prev, pager, next, jumper"
  183. :total="pageInfo.totalRec">
  184. </el-pagination>
  185. </div>
  186. </div>
  187. </div>
  188. <script type="text/javascript">
  189. document.write("<scr" + "ipt src=\"<%=commonPath%>/common/js/myjquery-a.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
  190. </script>
  191. <script src="<%=commonPath %>/common/js/common.js?V=<%=StaticValue.getJspImpVersion() %>"></script>
  192. <script src="<%=commonPath%>/common/i18n/i18nUtil.js"></script>
  193. <script type="text/javascript">
  194. if (browserData() !== -1) {
  195. document.write("<scr" + "ipt src=\"<%=commonPath%>/common/js/vue/babel.min.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
  196. }
  197. </script>
  198. <script type="text/javascript">
  199. if (browserData() !== -1) {
  200. document.write("<scr" + "ipt src=\"<%=commonPath%>/common/js/vue/browser-polyfill.min.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
  201. }
  202. </script>
  203. <script type="text/javascript">
  204. document.write("<scr" + "ipt src=\"<%=commonPath%>/common/js/vue/vue.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
  205. </script>
  206. <script type="text/javascript">
  207. document.write("<scr" + "ipt src=\"<%=commonPath%>/common/js/vue/index.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
  208. </script>
  209. <script type="text/javascript">
  210. if (browserData() === -1) {
  211. document.write("<scr" + "ipt src=\"<%=iPath %>/test.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
  212. }
  213. </script>
  214. <script src="<%=iPath %>/test.js?V=<%=StaticValue.getJspImpVersion() %>"
  215. type="text/babel"></script>
  216. </body>
  217. </html>

 

js

  1. $(function () {
  2. new Vue({
  3. el: "#container", //绑定jsp中div的id,可以理解为开始绑定vue
  4. data: { //data为定义jsp页面中需要的一些数据
  5. isSearch: true,
  6. isShow: false,
  7. isAdd : true,
  8. testForm: {
  9. id: '',
  10. cucuno: '',
  11. cutlno: '',
  12. cuopnt:'',
  13. remark:''
  14. },
  15. // 校验规则
  16. rules: {
  17. cucuno: [
  18. {required: true, message: '请输入客户号号', trigger: 'blur'},
  19. {min: 3, max: 3, message: '长度 3 个字符', trigger: 'blur'}
  20. ],
  21. cutlno: [
  22. {required: true, message: '请输入电话号码', trigger: 'blur'},
  23. {min: 6, max: 6, message: '长度在 6 个字符', trigger: 'blur'}
  24. ],
  25. cuopnt:[
  26. {required: true, message: '请输入客户号', trigger: 'blur'},
  27. {min: 3, max: 3, message: '长度在 3 个字符', trigger: 'blur'}
  28. ]
  29. },
  30. pageInfo: {
  31. pageIndex: 1, // 当前页数
  32. totalRec: 0, //数据总数
  33. pageSize: 15, // 每页条数
  34. pageSizeOpts: [5, 10, 15, 20, 50], // 每页条数切换的配置
  35. totalPage: 0 // 总页数
  36. },
  37. // 查询条件
  38. criteria: {
  39. phoneNo: "",
  40. acctNo: ""
  41. },
  42. loading: false,
  43. tableColumns: [],
  44. tableData: [],
  45. access: false,
  46. menuCode: '',
  47. position: '',
  48. emptyText: "请点击查询获取数据",
  49. delLoading: false
  50. },
  51. //钩子函数,vue所写页面,自动加载时执行这路面定义的属性
  52. created: function () {
  53. this.getInitData()
  54. this.getQuery()
  55. },
  56. //统一采用 _this 去 指向 this
  57. methods: {
  58. // 获取初始化参数的方法
  59. getInitData() {
  60. let _this = this
  61. $.ajax({
  62. type: "POST",
  63. url: 'que_siginInfomation.htm',
  64. data: "method=initData",
  65. dataType: 'json',
  66. async: false,
  67. success: function (result) {
  68. if (result) {
  69. let data = result.data
  70. _this.menuCode = data['menuCode']
  71. _this.position = data['position']
  72. _this.access = data['access']
  73. }
  74. },
  75. error: function () {
  76. _this.$message.error('很抱歉,连接异常!')
  77. }
  78. })
  79. },
  80. getQuery() {
  81. let _this = this;
  82. let query = {
  83. pageInfo: _this.pageInfo,
  84. criteria: _this.criteria
  85. }
  86. _this.loading = true
  87. $.ajax({
  88. type: "POST",
  89. url: 'que_siginInfomation.htm?method=query',
  90. data: JSON.stringify(query),
  91. dataType: 'json',
  92. contentType: "application/json",
  93. success: function (result) {
  94. if (result) {
  95. let data = result.data
  96. _this.tableData = data['data']
  97. _this.pageInfo.totalPage = data['totalPage']
  98. _this.pageInfo.totalRec = data['total']
  99. }
  100. _this.loading = false
  101. },
  102. error: function () {
  103. _this.loading = false
  104. _this.$message.error('很抱歉,连接异常!')
  105. }
  106. });
  107. },
  108. // 打开 add 页面
  109. add() {
  110. this.testForm = {
  111. id: '',
  112. cucuno: '',
  113. cutlno: '',
  114. cuopnt:'',
  115. remark:''
  116. }
  117. this.isShow = true
  118. },
  119. cancel() {
  120. this.isShow = false
  121. },
  122. doSubmit() {
  123. this.loading = true
  124. this.$refs['testForm'].validate((valid) => {
  125. if (valid) {
  126. alert("新增成功");
  127. this.loading = false
  128. this.isShow = false
  129. // 对页面进行刷新
  130. this.getQuery()
  131. } else {
  132. alert("参数校验不通过");
  133. this.loading = false
  134. return false
  135. }
  136. })
  137. },
  138. subDelete(id) {
  139. this.delLoading = true
  140. alert("删除成功id为"+id+"的数据");
  141. this.$refs[id].doClose()
  142. this.delLoading = false
  143. this.getQuery()
  144. },
  145. edit(row) {
  146. this.testForm = {
  147. id: row.id,
  148. cucuno: row.cucuno,
  149. cutlno: row.cutlno,
  150. cuopnt: row.cuopnt,
  151. remark:''
  152. }
  153. this.isAdd = false
  154. this.isShow = true
  155. },
  156. // 更改分页
  157. handlePage(value) {
  158. this.pageInfo.pageIndex = value
  159. this.getQuery()
  160. },
  161. handlePageSize(value) {
  162. this.pageInfo.pageSize = value
  163. this.getQuery()
  164. }
  165. }
  166. })
  167. })

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/300084
推荐阅读