当前位置:   article > 正文

【实用模板】Vue代码文件常用后台管理页面模板

【实用模板】Vue代码文件常用后台管理页面模板
  1. <template>
  2. <div
  3. :class="$options.name"
  4. v-loading="loading"
  5. :element-loading-text="elementLoadingText"
  6. ></div>
  7. <sgSearch
  8. :collapse.sync="collapseSearch"
  9. @keyup.enter="(collapseSearch = true), (currentPage = 1), initList()"
  10. @getHeight="(d) => (sgSearchHeight = d)"
  11. >
  12. <template slot="searchFilter">
  13. <li>
  14. <label>搜索</label>
  15. <el-input clearable placeholder="请输入关键词" v-model.trim="keyword" />
  16. </li>
  17. <li style="width: 150px">
  18. <label>状态</label>
  19. <el-select style="width: 100%" v-model="ZT" placeholder="请选择" clearable>
  20. <el-option
  21. v-for="(a, i) in ZTs"
  22. :key="i"
  23. :value="a.value"
  24. :label="a.label"
  25. ></el-option>
  26. </el-select>
  27. </li>
  28. <li>
  29. <label>更新时间</label>
  30. <el-date-picker
  31. v-model="GXSJ"
  32. ref="GXSJ"
  33. type="daterange"
  34. align="right"
  35. unlink-panels
  36. range-separator="至"
  37. start-placeholder="开始日期"
  38. end-placeholder="结束日期"
  39. :picker-options="$global.pickerOptions"
  40. clearable
  41. />
  42. </li>
  43. </template>
  44. <template slot="searchBtns">
  45. <el-button
  46. size="medium"
  47. type="primary"
  48. icon="el-icon-search"
  49. @click="(collapseSearch = true), (currentPage = 1), initList()"
  50. >搜索</el-button
  51. >
  52. <el-button size="medium" type="primary" @click="resetFilterData(), initList()" plain
  53. >重置</el-button
  54. >
  55. </template>
  56. <template slot="operateBtns">
  57. <el-button size="medium" type="primary" @click="add">添加</el-button>
  58. <el-button
  59. :disabled="selection.length === 0"
  60. size="medium"
  61. type="danger"
  62. @click="delAny"
  63. >批量删除</el-button
  64. >
  65. </template>
  66. </sgSearch>
  67. <div
  68. class="sg-table"
  69. v-loading="loading"
  70. :full="fullscreenTable"
  71. @click="collapseSearch = true"
  72. >
  73. <el-table
  74. :data="tableData"
  75. ref="table"
  76. stripe
  77. border
  78. :header-cell-style="{ background: '#f5f7fa' }"
  79. :height="`calc(100vh - ${fullscreenTable ? 10 : 160 + sgSearchHeight}px - ${
  80. total > 10 ? 40 : 0
  81. }px)`"
  82. :show-header="true"
  83. style="width: 100%"
  84. @row-click="row_click"
  85. @selection-change="selection_change"
  86. :row-class-name="row_class_name"
  87. >
  88. <template slot="empty">
  89. <el-empty v-show="!loading" :image="require('@/assets/404.png')">
  90. <span slot="description">暂无数据</span>
  91. <el-button type="primary" icon="el-icon-s-promotion" plain @click="add"
  92. >去添加数据</el-button
  93. >
  94. </el-empty>
  95. </template>
  96. <el-table-column type="selection" width="50" />
  97. <el-table-column
  98. type="index"
  99. label="序号"
  100. width="60"
  101. :index="(index) => (currentPage - 1) * pageSize + index + 1"
  102. />
  103. <!-- 主要列 BEGIN---------------------------------------- -->
  104. <el-table-column prop="字段" label="列名" minWidth="200" />
  105. <el-table-column :resizable="false" prop="ID" label="身份证号" minWidth="200">
  106. <template v-slot:header="scope">
  107. <span>
  108. 身份证号
  109. <fullscreenTable v-model="fullscreenTable" />
  110. </span>
  111. </template>
  112. <template slot-scope="scope">
  113. <span>【索引{{ scope.$index }}】{{ scope.row.ID }}</span>
  114. </template>
  115. </el-table-column>
  116. <el-table-column label="用户名" show-overflow-tooltip minWidth="100">
  117. <template slot-scope="scope">
  118. <span>{{ scope.row.username }}</span>
  119. </template>
  120. </el-table-column>
  121. <el-table-column label="姓名" show-overflow-tooltip minWidth="80">
  122. <template slot-scope="scope">
  123. <span>{{ scope.row.name }}</span>
  124. </template>
  125. </el-table-column>
  126. <el-table-column label="权限角色" show-overflow-tooltip minWidth="100">
  127. <template slot-scope="scope">
  128. <span>{{ scope.row.role || `未分配` }}</span>
  129. </template>
  130. </el-table-column>
  131. <!-- 主要列 END---------------------------------------- -->
  132. <el-table-column label="操作" width="175">
  133. <template slot-scope="scope">
  134. <el-button
  135. size="mini"
  136. type="primary"
  137. @click.stop="edit(scope.row)"
  138. @dblclick.native.stop
  139. >修改</el-button
  140. >
  141. <el-button
  142. size="mini"
  143. type="danger"
  144. @click.stop="del(scope.row)"
  145. @dblclick.native.stop
  146. >删除</el-button
  147. >
  148. </template>
  149. </el-table-column>
  150. </el-table>
  151. <el-pagination
  152. style="width: 100%; text-align: center; margin-top: 10px"
  153. background
  154. :hidden="total <= 10"
  155. :layout="`total, sizes, prev, pager, next, jumper`"
  156. :page-sizes="[10, 20, 50, 100]"
  157. :pager-count="7"
  158. :current-page.sync="currentPage"
  159. :page-size.sync="pageSize"
  160. :total="total"
  161. @size-change="initList"
  162. @current-change="initList"
  163. />
  164. </div>
  165. </template>
  166. <script>
  167. import sgSearch from "@/vue/components/admin/sgSearch";
  168. export default {
  169. name: "组件模板",
  170. components: {
  171. sgSearch,
  172. },
  173. data() {
  174. return {
  175. loading: false, //加载状态
  176. elementLoadingText: ``, //加载提示文字
  177. visible: false, //是否显示
  178. forbid: false, //是否禁用
  179. form: {}, //表单信息
  180. showEditDrawer: false, //显示编辑抽屉
  181. editDrawerData: null, //抽屉数据
  182. collapseSearch: false, //折叠搜索栏
  183. keyword: "", //搜索关键词
  184. ZT: 1, //当前状态
  185. ZTs: [
  186. { value: 1, label: "显示文本1" },
  187. { value: 2, label: "显示文本2" },
  188. { value: 3, label: "显示文本3" },
  189. { value: 4, label: "显示文本4" },
  190. { value: 5, label: "显示文本5" },
  191. ],
  192. GXSJ: [], //更新时间
  193. fullscreenTable: false, //全屏表格
  194. sgSearchHeight: 0, //搜索栏的高度(或者相关选项卡组件的高度)
  195. tableData: [
  196. { ID: "330110198704103091", username: "username1", name: "姓名1", role: "role1" },
  197. { ID: "330110198704103092", username: "username2", name: "姓名2", role: "role2" },
  198. { ID: "330110198704103093", username: "username3", name: "姓名3", role: "role3" },
  199. { ID: "330110198704103094", username: "username4", name: "姓名4", role: "role4" },
  200. { ID: "330110198704103095", username: "username5", name: "姓名5", role: "role5" },
  201. ], //表格数据
  202. selection: [], //表格选中项数组
  203. currentPage: 1,
  204. pageSize: 10,
  205. total: 0,
  206. //total: 999,
  207. };
  208. },
  209. props: [
  210. "value", //是否显示
  211. "disabled", //是否禁用
  212. "data",
  213. ],
  214. computed: {},
  215. watch: {
  216. loading(newValue, oldValue) {
  217. newValue || (this.elementLoadingText = ``);
  218. },
  219. value: {
  220. handler(d) {
  221. this.visible = d;
  222. },
  223. deep: true,
  224. immediate: true,
  225. },
  226. visible(d) {
  227. this.$emit("input", d);
  228. }, //是否显示(双向绑定)
  229. disabled: {
  230. handler(d) {
  231. this.forbid = d;
  232. },
  233. deep: true,
  234. immediate: true,
  235. },
  236. forbid(d) {
  237. this.$emit(`update:disabled`, d);
  238. }, //是否显示(双向绑定)
  239. data: {
  240. handler(newValue, oldValue) {
  241. //console.log('深度监听:', newValue, oldValue);
  242. if (newValue && Object.keys(newValue).length) {
  243. this.form = JSON.parse(JSON.stringify(newValue));
  244. } else {
  245. this.form = {};
  246. }
  247. },
  248. deep: true, //深度监听
  249. immediate: true, //立即执行
  250. },
  251. },
  252. created() {
  253. this.init();
  254. },
  255. mounted() {},
  256. destroyed() {},
  257. methods: {
  258. row_click(row, column, event) {
  259. this.$refs.table.toggleRowSelection(row);
  260. },
  261. selection_change(selection) {
  262. this.selection = selection;
  263. },
  264. row_class_name({ row, rowIndex }) {
  265. return this.selection.some((v) => v.ID === row.ID) ? "selected" : "";
  266. },
  267. //初始化
  268. init({ d } = {}) {
  269. this.initData();
  270. },
  271. //初始化数据
  272. initData({ d } = {}) {
  273. this.initList();
  274. },
  275. // 重置
  276. reset(d) {
  277. this.resetFilterData(), this.initList();
  278. },
  279. // 重置筛选条件
  280. resetFilterData(d) {
  281. this.currentPage = 1;
  282. this.keyword = "";
  283. this.GXSJ = [];
  284. },
  285. //初始化列表
  286. initList({ keyword = this.keyword } = {}) {
  287. this.collapseSearch = true;
  288. // 更新时间
  289. let KSSJ = this.$g.date.get_yyyy_MM_dd(this.GXSJ[0]); //开始时间
  290. let JSSJ = this.$g.date.get_yyyy_MM_dd(this.GXSJ[1]); //结束时间
  291. let data = {
  292. KEYS: keyword,
  293. KSSJ,
  294. JSSJ,
  295. start: this.currentPage - 1, //当前页数(从0开始)
  296. limit: this.pageSize, //每页显示条目个数
  297. sgLog: `前端请求来源:${this.$options.name}查询数据接口`,
  298. };
  299. this.$d.查询数据接口({
  300. data,
  301. r: {
  302. l: { show: () => (this.loading = true), close: () => (this.loading = false) },
  303. s: (d) => {
  304. this.tableData = d.data; //列表数据赋值
  305. this.tableData.sort((prev, next) => prev.RANK - next.RANK); //从小到大升序(会改变原数组)
  306. this.total = d.totalCount; //总条数
  307. },
  308. },
  309. });
  310. },
  311. add(d) {
  312. this.editDrawerData = null;
  313. this.showEditDrawer = true;
  314. },
  315. edit(d) {
  316. this.editDrawerData = JSON.parse(JSON.stringify(d));
  317. this.showEditDrawer = true;
  318. },
  319. delAny() {
  320. this.del(this.selection);
  321. },
  322. del(arr) {
  323. Array.isArray(arr) || (arr = [arr]);
  324. this.$confirm(
  325. `此操作将永久删除${arr.length > 1 ? `这${arr.length}个` : `此`}数据,是否继续?`,
  326. `提示`,
  327. {
  328. dangerouslyUseHTMLString: true,
  329. confirmButtonText: `确定`,
  330. cancelButtonText: `取消`,
  331. type: "warning",
  332. }
  333. )
  334. .then(() => {
  335. let data = {
  336. IDS: arr.map((v) => v.ID),
  337. sgLog: `前端请求来源:${this.$options.name}删除数据接口`,
  338. };
  339. this.$d.删除数据接口({
  340. data,
  341. r: {
  342. l: {
  343. show: () => (this.loading = true),
  344. close: () => (this.loading = false),
  345. },
  346. s: (d) => {
  347. this.initList();
  348. this.$message.success(arr.length > 1 ? `批量删除成功` : `已删除`);
  349. },
  350. },
  351. });
  352. })
  353. .catch(() => {
  354. //this.$message(`已取消删除`);
  355. });
  356. },
  357. valid(d) {
  358. // if (!this.form.MC) return this.$message.error(this.$refs.MC.$el.querySelector("input").placeholder);
  359. },
  360. save() {
  361. if (this.valid()) return;
  362. if (this.form.ID) {
  363. // 修改
  364. } else {
  365. // 新增
  366. }
  367. let data = {
  368. ...this.form,
  369. sgLog: `前端请求来源:${this.$options.name}保存数据接口`,
  370. };
  371. this.$d.保存数据接口({
  372. data,
  373. r: {
  374. l: { show: () => (this.loading = true), close: () => (this.loading = false) },
  375. s: (d) => {
  376. this.initList({ keyword: "" });
  377. this.$emit(`save`, this.form);
  378. this.cancel(this.form);
  379. },
  380. },
  381. });
  382. },
  383. cancel(d) {
  384. this.$emit(`hide`, d);
  385. },
  386. },
  387. };
  388. </script>
  389. <style lang="scss" scoped>
  390. .组件模板 {
  391. }
  392. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/274406
推荐阅读
相关标签
  

闽ICP备14008679号