浏览代码

fix(category/user): fix

furffico 1 年之前
父节点
当前提交
2027f7133b

+ 1 - 1
src/crud/prod/category.ts → src/avue/crud/category.ts

@@ -7,7 +7,7 @@ export const tableOption = {
     menuAlign: 'center',
     menuFixed: false,
     align: 'center',
-    refreshBtn: true,
+    refreshBtn: false,
     searchSize: 'mini',
     addBtn: true,
     editBtn: true,

+ 0 - 0
src/crud/user/user.js → src/avue/crud/user.js


+ 22 - 0
src/utils/vo.ts

@@ -0,0 +1,22 @@
+
+export interface ICategory {
+  id: number
+  name: string
+  adminId: number
+}
+
+export interface IUser {
+  id: number
+  nickname: string
+  phone: string
+  role: string
+  phoneHidden: string
+  createdAt: string
+}
+
+export type IPage = Record<"total" | "currentPage" | "pageSize", number>
+interface IPageData<T> {
+  // 后端返回的格式不统一,这个用不了
+  total: number
+  items: T[]
+}

+ 0 - 14
src/utils/vo/index.ts

@@ -1,14 +0,0 @@
-
-export interface ICategory {
-    id: number
-    name: string
-    adminId: number
-  }
-  
-export type IPage = Record<"total" | "currentPage" | "pageSize", number>
-
-interface IPageData<T>{
-  // 后端返回的格式不统一,这个用不了
-  total: number
-  items: T[]
-}

+ 7 - 3
src/views/modules/prod/category.vue

@@ -1,12 +1,12 @@
 <template>
   <avue-crud ref="crud" :page="page" :data="dataList" :table-loading="dataListLoading" :option="tableOption"
-    @on-load="getDataList" @row-update="updateItem" @row-del="deleteItem" @row-save="addItem">
+    @on-load="getDataList" @row-update="updateItem" @row-del="deleteItem" @row-save="addItem" @search-change="searchChange">
   </avue-crud>
 </template>
 
 <script lang="ts">
 import Vue from 'vue'
-import { tableOption } from '@/crud/prod/category'
+import { tableOption } from '@/avue/crud/category'
 import { httpx, AxiosPromise, AxiosResponse } from "@/utils/httpx"
 import { ceil, clone } from 'lodash'
 import { ICategory, IPage } from '@/utils/vo'
@@ -84,6 +84,10 @@ export default Vue.extend({
       })
     },
 
+    searchChange (params: ICategory, done?: Function) {
+      this.getDataList(this.page, params, done)
+    },
+
     deleteItem({ id }: ICategory) {
       return this.$confirm(`确定进行删除操作?`, '提示', {
         confirmButtonText: '确定',
@@ -102,4 +106,4 @@ export default Vue.extend({
     }
   }
 })
-</script>
+</script>@/avue/crud/category

+ 0 - 109
src/views/modules/user/user-add-or-update.vue

@@ -1,109 +0,0 @@
-<template>
-  <el-dialog :title="!dataForm.userId ? '新增' : '修改'"
-             :close-on-click-modal="false"
-             :visible.sync="visible">
-    <el-form :model="dataForm"
-             :rules="dataRule"
-             ref="dataForm"
-             @keyup.enter.native="dataFormSubmit()"
-             label-width="80px">
-      <!--el-form-item label="用户头像"
-                    prop="pic">
-        <img :src="dataForm.pic"
-             class="image">
-      </el-form-item-->
-      <el-form-item label="用户昵称"
-                    prop="nickName">
-        <el-input v-model="dataForm.nickName"
-                  :disabled="true"
-                  placeholder="用户昵称"></el-input>
-      </el-form-item>
-      <el-form-item label="状态"
-                    size="mini"
-                    prop="status">
-        <el-radio-group v-model="dataForm.status">
-          <el-radio :label="0">禁用</el-radio>
-          <el-radio :label="1">正常</el-radio>
-        </el-radio-group>
-      </el-form-item>
-    </el-form>
-    <span slot="footer"
-          class="dialog-footer">
-      <el-button @click="visible = false">取消</el-button>
-      <el-button type="primary"
-                 @click="dataFormSubmit()">确定</el-button>
-    </span>
-  </el-dialog>
-</template>
-
-<script>
-import { Debounce } from '@/utils/debounce'
-export default {
-  data () {
-    return {
-      visible: false,
-      dataForm: {
-        userId: 0,
-        nickName: '',
-        pic: '',
-        status: 1
-      },
-      page: {
-        total: 0, // 总页数
-        currentPage: 1, // 当前页数
-        pageSize: 10 // 每页显示多少条
-      },
-      resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
-      dataRule: {
-        nickName: [
-          { required: true, message: '用户名不能为空', trigger: 'blur' }
-        ]
-      }
-    }
-  },
-  methods: {
-    init (id) {
-      this.dataForm.userId = id || 0
-      this.visible = true
-      this.$nextTick(() => {
-        this.$refs.dataForm.resetFields()
-      })
-      if (this.dataForm.userId) {
-        this.$http({
-          url: this.$http.adornUrl(`/admin/user/info/${this.dataForm.userId}`),
-          method: 'get',
-          params: this.$http.adornParams()
-        }).then(({ data }) => {
-          this.dataForm = data
-        })
-      }
-    },
-    // 表单提交
-    dataFormSubmit: Debounce(function () {
-      this.$refs['dataForm'].validate(valid => {
-        if (valid) {
-          this.$http({
-            url: this.$http.adornUrl(`/admin/user`),
-            method: this.dataForm.userId ? 'put' : 'post',
-            data: this.$http.adornData({
-              userId: this.dataForm.userId || undefined,
-              nickName: this.dataForm.nickName,
-              status: this.dataForm.status
-            })
-          }).then(({ data }) => {
-            this.$message({
-              message: '操作成功',
-              type: 'success',
-              duration: 1500,
-              onClose: () => {
-                this.visible = false
-                this.$emit('refreshDataList', this.page)
-              }
-            })
-          })
-        }
-      })
-    })
-  }
-}
-</script>

+ 36 - 74
src/views/modules/user/user.vue

@@ -1,59 +1,54 @@
 <template>
-  <div class="mod-user">
-    <avue-crud ref="crud" :page="page" :data="dataList" :option="tableOption" @search-change="searchChange"
-      @selection-change="selectionChange" @on-load="getDataList"
-      @row-del="deleteUser">
-      <!--      <template slot="menuLeft">-->
-      <!--        <el-button type="danger"-->
-      <!--                   @click="deleteHandle()"-->
-      <!--                   v-if="isAuth('admin:user:delete')"-->
-      <!--                   size="small"-->
-      <!--                   :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
-      <!--      </template>-->
-
-      <template slot-scope="scope" slot="pic">
-        <span class="avue-crud__img" v-if="scope.row.pic">
-          <i :src="scope.row.pic" class="el-icon-document"></i>
-        </span>
-        <span v-else>-</span>
-      </template>
-
-      <template slot-scope="scope" slot="status">
-        <el-tag v-if="scope.row.status === 0" size="small" type="danger">禁用</el-tag>
-        <el-tag v-else size="small">正常</el-tag>
-      </template>
-    </avue-crud>
-
-    <!-- 弹窗, 新增 / 修改 -->
-    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
-  </div>
+  <avue-crud ref="crud" :page="page" :data="dataList" :option="tableOption" 
+    @search-change="searchChange" @on-load="getDataList" @row-del="deleteUser">
+  </avue-crud>
+  <!-- 弹窗, 新增 / 修改 -->
+  <!--add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update-->
 </template>
 
-<script>
-import { tableOption } from '@/crud/user/user'
-import AddOrUpdate from './user-add-or-update'
+<script lang="ts" >
+import { tableOption } from '@/avue/crud/user'
 import Axios from 'axios'
+import {IUser, IPage} from "@/utils/vo"
+import Vue from "vue"
 
-export default {
+export default Vue.extend({
   data() {
     return {
-      dataList: [],
+      dataList: [] as IUser[],
       dataListLoading: false,
-      dataListSelections: [],
-      addOrUpdateVisible: false,
+      // dataListSelections: [],
+      // addOrUpdateVisible: false,
       tableOption: tableOption,
       page: {
         total: 1, // 总页数
         currentPage: 1, // 当前页数
         pageSize: 10 // 每页显示多少条
-      }
+      } as IPage,
     }
   },
-  components: {
-    AddOrUpdate
-  },
   methods: {
-    deleteUser(user){
+    // 获取数据列表
+    getDataList(page?: IPage, params?: Partial<IUser>, done?: Function) {
+      this.dataListLoading = true
+      Axios.post('/user/queryUserList',{
+          phone: params?.phone || "",
+          nickName: params?.nickname || "",
+          limit: page == null ? this.page.pageSize : page.pageSize,
+          page: page == null ? this.page.currentPage : page.currentPage,
+      }).then(({data})=>{
+        this.dataList = data.data.userList
+        this.page.total = data.data.total
+        this.dataListLoading = false
+        if (done) { done() }
+      })
+    },
+    // 条件查询
+    searchChange(params: Partial<IUser>, done?: Function) {
+      this.getDataList(this.page, params, done)
+    },
+
+    deleteUser(user: IUser){
       this.$confirm(`确定进行删除操作?`, '提示', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
@@ -74,39 +69,6 @@ export default {
         })
       })
     },
-    // 获取数据列表
-    getDataList(page, params, done) {
-      this.dataListLoading = true
-      Axios.post(this.$http.adornUrl('/user/queryUserList'),
-      Object.assign({
-          phone: "",
-          nickName: "",
-          limit: page == null ? this.page.pageSize : page.pageSize,
-          page: page == null ? this.page.currentPage : page.currentPage,
-      },params)).then(({data})=>{
-        this.dataList = data.data.userList
-        this.page.total = data.data.total
-        this.dataListLoading = false
-        if (done) {
-          done()
-        }
-      })
-    },
-    // 新增 / 修改
-    addOrUpdateHandle(id) {
-      this.addOrUpdateVisible = true
-      this.$nextTick(() => {
-        this.$refs.addOrUpdate.init(id)
-      })
-    },
-    // 条件查询
-    searchChange(params, done) {
-      this.getDataList(this.page, params, done)
-    },
-    // 多选变化
-    selectionChange(val) {
-      this.dataListSelections = val
-    }
   }
-}
+})
 </script>