Browse Source

个人详情和图片

Alex 4 years ago
parent
commit
5fa7a52004

+ 53 - 0
src/api/system/profile.js

@@ -0,0 +1,53 @@
+import request from '@/utils/request'
+
+// 查询个人详情列表
+export function listProfile(query) {
+  return request({
+    url: '/system/profile/list',
+    method: 'get',
+    params: query
+  })
+}
+
+// 查询个人详情详细
+export function getProfile(id) {
+  return request({
+    url: '/system/profile/' + id,
+    method: 'get'
+  })
+}
+
+// 新增个人详情
+export function addProfile(data) {
+  return request({
+    url: '/system/profile',
+    method: 'post',
+    data: data
+  })
+}
+
+// 修改个人详情
+export function updateProfile(data) {
+  return request({
+    url: '/system/profile',
+    method: 'put',
+    data: data
+  })
+}
+
+// 删除个人详情
+export function delProfile(id) {
+  return request({
+    url: '/system/profile/' + id,
+    method: 'delete'
+  })
+}
+
+// 导出个人详情
+export function exportProfile(query) {
+  return request({
+    url: '/system/profile/export',
+    method: 'get',
+    params: query
+  })
+}

+ 71 - 0
src/api/system/profileImg.js

@@ -0,0 +1,71 @@
+import request from '@/utils/request'
+
+// 查询图片列表
+export function listProfileImg(query) {
+  return request({
+    url: '/system/profile/img/list',
+    method: 'get',
+    params: query
+  })
+}
+// 查询图片列表
+export function allProfileImg(query) {
+  return request({
+    url: '/system/profile/img/all',
+    method: 'get',
+    params: query
+  })
+}
+
+// 查询图片详细
+export function getProfileImg(id) {
+  return request({
+    url: '/system/profile/img/' + id,
+    method: 'get'
+  })
+}
+
+// 新增图片
+export function addProfileImg(data) {
+  return request({
+    url: '/system/profile/img',
+    method: 'post',
+    data: data
+  })
+}
+
+// 修改图片
+export function updateProfileImg(data) {
+  return request({
+    url: '/system/profile/img',
+    method: 'put',
+    data: data
+  })
+}
+
+// 删除图片
+export function delProfileImg(id) {
+  return request({
+    url: '/system/profile/img/del/' + id,
+    method: 'get'
+  })
+}
+
+// 导出图片
+export function exportProfileImg(query) {
+  return request({
+    url: '/system/profile/img/export',
+    method: 'get',
+    params: query
+  })
+}
+
+
+// 上传图片 
+export function uploadFile(data) {
+  return request({
+    url: '/system/profile/img/upload',
+    method: 'post',
+    data: data
+  })
+}

+ 200 - 0
src/views/system/appUser/detail/profileImg.vue

@@ -0,0 +1,200 @@
+<template>
+    <div style="margin:10px;">
+
+      <el-form>
+        <el-col :offset="1">
+        <el-form-item label-width="0px" prop="picture" style="width: 100%;">
+            <el-upload ref="upload"
+                action="#"
+                list-type="picture-card"
+                :on-preview="handlePictureCardPreview"
+                :on-remove="handleRemove"
+                :http-request="uploadAvatar"
+                :before-upload="beforeAvatarUpload"
+                :file-list="fileList"
+            >
+                <i class="el-icon-plus"></i>
+            </el-upload>
+            <el-dialog :visible.sync="dialogVisible">
+                <img width="100%" :src="dialogImageUrl" alt="">
+            </el-dialog>
+        </el-form-item>
+        </el-col>
+
+        <el-col :span="6" v-for="(item,index) in picList" :offset="1" :style="{ padding: '0px 0px 10px' }" :key="item.key">
+            <div @mouseover="enter(index)" @mouseleave="leave">
+                <el-card :body-style="{ padding: '0px' }" shadow="always" class="father">
+                <el-image  :key="item.value" :src="item.value" :preview-src-list="[item.value]" class="image"></el-image>
+                <div class="son" v-show="num==index" @click="delImg(item.key,index)">
+                    <i class="el-icon-delete" style="color:#fff"></i>
+                </div>
+             </el-card>
+            </div>
+        </el-col>
+      </el-form>
+    </div>
+</template>
+
+<script>
+import { uploadFile,allProfileImg,delProfileImg } from "@/api/system/profileImg";
+
+export default {
+  name: "ProfileImg",
+  data() {
+    return {
+        dialogImageUrl: '',
+        dialogVisible: false,
+        picList: [],
+        fileList: [],
+        profileImg: {
+            profileId: null,
+            url: null
+        },
+        num: -1,
+    };
+  },
+  created() {
+    const pid = this.$route.query.pid;
+    this.profileImg.profileId = pid;
+    this.getList(pid);
+  },
+  methods: {
+    getList(pid){ 
+        allProfileImg(this.profileImg).then(res => {
+            if(res.code !== 200){
+                this.$message.error('获取照片列表失败')
+                return
+            }
+            this.picList = [];
+            var apiUrl = process.env.VUE_APP_BASE_API;
+            var items = res.data;
+            for (const i in items) {
+                var url = apiUrl + items[i].url;
+                this.picList.push({ key: items[i].id, value: url})
+            }
+            console.log( this.picList)
+        })
+    },
+    uploadAvatar(item) {  
+        const formData = new FormData()
+        const pid = this.profileImg.profileId;
+        formData.append('file', item.file)
+        formData.append('profileId', pid)
+        const uid = item.file.uid
+        uploadFile(formData).then(res => {
+            this.emptyUpload()
+            this.getList(pid)
+            // this.picList.push({ key: uid, value: res.url })
+        }).catch(() => {
+            this.$message.error('上传失败,请重新上传')
+            this.emptyUpload()
+        })
+    },
+    beforeAvatarUpload(file) { 
+        const isJPG = file.type === 'image/jpeg';
+        const isPng = file.type === 'image/png';
+        const isLt2M = file.size / 1024 / 1024 < 2;
+
+        if (!isJPG && !isPng) {
+            this.$message.error('上传图片只能是 JPG或png 格式!')
+        }
+        if (!isLt2M) {
+            this.$message.error('上传图片大小不能超过 2MB!')
+        }
+        return (isJPG || isPng) && isLt2M
+    },
+    handleRemove(file, fileList) {
+        for (const i in this.picList) {
+        if (this.picList[i].key === file.uid) {
+            this.picList.splice(i, 1)
+        }
+        }
+    },
+    handlePictureCardPreview(file) {
+        this.dialogImageUrl = file.url
+        this.dialogVisible = true
+    },
+    /**
+     * 清空上传组件
+     */
+    emptyUpload() {
+        const mainImg = this.$refs.upload
+        if (mainImg) {
+            if (mainImg.length) {
+                mainImg.forEach(item => {
+                    item.clearFiles()
+                })
+            } else {
+                this.$refs.upload.clearFiles()
+            }
+        }
+    },
+    enter(index){ 
+        this.num = index;
+    },
+    leave(){ 
+        this.num = -1;
+    },
+    delImg(_id,index){
+        var listItem = this.picList;
+        const imgId = _id; 
+        this.$confirm('确认删除这张照片?', "警告", {
+          confirmButtonText: "确定",
+          cancelButtonText: "取消",
+          type: "warning"
+        }).then(function() {
+            delProfileImg(imgId).then(res => {
+                if(res.code === 200) {
+                    listItem.splice(index,1);
+                    this.picList = listItem;
+                }
+            })
+        }).catch(function() {});
+    }
+  }
+}
+</script>
+
+
+<style>
+.father{
+    position: relative;
+}
+.son{
+    position: absolute;
+    z-index: 999;
+    width: 100%;
+    background: rgba(0,0,0,0.5);
+    bottom: 0;
+    left: 0;
+    right: 0;
+    text-align: center;
+    padding: 5px 0;
+}
+.disn{
+    visibility: visible;
+}
+ .el-upload-list--picture-card .el-upload-list__item {
+     height: auto;
+     width: 20%;
+     vertical-align: middle;
+ }
+ .image {
+    width: 100%;
+    display: block;
+  }
+.button {
+    padding: 5px 0;
+    display: flex;
+    align-content: center;
+    justify-items: center;
+  }
+  .clearfix:before, .clearfix:after {
+      display: table;
+      content: "";
+  }
+  
+  .clearfix:after {
+      clear: both
+  }
+</style>

+ 301 - 0
src/views/system/appUser/detail/profiles.vue

@@ -0,0 +1,301 @@
+<template>
+  <div class="app-container">
+    <span><i class="el-icon-user"></i> 个人详情 - {{nickName}}</span>
+    <el-divider></el-divider>
+    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
+      <el-form-item label="标题" prop="title">
+        <el-input
+          v-model="queryParams.title"
+          placeholder="请输入标题"
+          clearable
+          size="small"
+          @keyup.enter.native="handleQuery"
+        />
+      </el-form-item>
+      <el-form-item>
+        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
+        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
+      </el-form-item>
+    </el-form>
+
+    <el-row :gutter="10" class="mb8">
+      <el-col :span="1.5">
+        <el-button
+          type="primary"
+          icon="el-icon-plus"
+          size="mini"
+          @click="handleAdd"
+          v-hasPermi="['system:profile:add']"
+        >新增</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="success"
+          icon="el-icon-edit"
+          size="mini"
+          :disabled="single"
+          @click="handleUpdate"
+          v-hasPermi="['system:profile:edit']"
+        >修改</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="danger"
+          icon="el-icon-delete"
+          size="mini"
+          :disabled="multiple"
+          @click="handleDelete"
+          v-hasPermi="['system:profile:remove']"
+        >删除</el-button>
+      </el-col>
+	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
+    </el-row>
+
+    <el-table v-loading="loading" :data="profileList" @selection-change="handleSelectionChange">
+      <el-table-column type="selection" width="55" align="center" />
+      <el-table-column label="id" align="center" prop="id" v-if="false" />
+      <el-table-column label="标题" align="center" prop="title" />
+      <el-table-column label="内容" align="center" prop="cotents" :formatter="contentsFormat"/>
+      <el-table-column label="备注" align="center" prop="remark" />
+      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
+        <template slot-scope="scope">
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-picture-outline"
+            @click="handleImg(scope.row)"
+            v-hasPermi="['system:profile:edit']"
+          >图片</el-button>
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-edit"
+            @click="handleUpdate(scope.row)"
+            v-hasPermi="['system:profile:edit']"
+          >修改</el-button>
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-delete"
+            @click="handleDelete(scope.row)"
+            v-hasPermi="['system:profile:remove']"
+          >删除</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+    
+    <pagination
+      v-show="total>0"
+      :total="total"
+      :page.sync="queryParams.pageNum"
+      :limit.sync="queryParams.pageSize"
+      @pagination="getList"
+    />
+
+    <!-- 添加或修改个人详情对话框 -->
+    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
+      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
+        <el-form-item label="标题" prop="title">
+          <el-input v-model="form.title" placeholder="请输入标题" />
+        </el-form-item>
+        <el-form-item label="内容" prop="cotents">
+          <el-input v-model="form.cotents" type="textarea" placeholder="请输入内容" />
+        </el-form-item>
+        <el-form-item label="备注" prop="remark">
+          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="submitForm">确 定</el-button>
+        <el-button @click="cancel">取 消</el-button>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import { listProfile, getProfile, delProfile, addProfile, updateProfile, exportProfile } from "@/api/system/profile";
+import { getUser } from "@/api/system/appUser";
+
+export default {
+  name: "Profile",
+  data() {
+    return {
+      nickName: "",
+      // 遮罩层
+      loading: true,
+      // 选中数组
+      ids: [],
+      // 非单个禁用
+      single: true,
+      // 非多个禁用
+      multiple: true,
+      // 显示搜索条件
+      showSearch: true,
+      // 总条数
+      total: 0,
+      // 个人详情表格数据
+      profileList: [],
+      // 弹出层标题
+      title: "",
+      // 是否显示弹出层
+      open: false,
+      // 查询参数
+      queryParams: {
+        pageNum: 1,
+        pageSize: 10,
+        appUserId: null,
+        title: null,
+        cotents: null,
+      },
+      // 表单参数
+      form: {},
+      // 表单校验
+      rules: {
+      }
+    };
+  },
+  created() {
+    const uid = this.$route.query.uid;
+    this.queryParams.appUserId = uid;
+    this.getUser(uid);
+    this.getList();
+  },
+  methods: {
+      getUser(id){
+        getUser(id).then(response => {
+            const nickName = response.data.nickName;
+            this.nickName = nickName == null ? "全部" : nickName;
+        });
+      },
+    /** 查询个人详情列表 */
+    getList() {
+      this.loading = true;
+      listProfile(this.queryParams).then(response => {
+        this.profileList = response.rows;
+        this.total = response.total;
+        this.loading = false;
+      });
+    },
+    // 取消按钮
+    cancel() {
+      this.open = false;
+      this.reset();
+    },
+    // 表单重置
+    reset() {
+      this.form = {
+        id: null,
+        appUserId: null,
+        title: null,
+        cotents: null,
+        createBy: null,
+        createTime: null,
+        updateBy: null,
+        updateTime: null,
+        remark: null
+      };
+      this.resetForm("form");
+    },
+    /** 搜索按钮操作 */
+    handleQuery() {
+      this.queryParams.pageNum = 1;
+      this.getList();
+    },
+    /** 重置按钮操作 */
+    resetQuery() {
+      this.resetForm("queryForm");
+      this.handleQuery();
+    },
+    // 多选框选中数据
+    handleSelectionChange(selection) {
+      this.ids = selection.map(item => item.id)
+      this.single = selection.length!==1
+      this.multiple = !selection.length
+    },
+    /** 新增按钮操作 */
+    handleAdd() {
+      this.reset();
+      this.open = true;
+      this.title = "添加个人详情";
+    },
+    /** 修改按钮操作 */
+    handleUpdate(row) {
+      this.reset();
+      const id = row.id || this.ids
+      getProfile(id).then(response => {
+        this.form = response.data;
+        this.open = true;
+        this.title = "修改个人详情";
+      });
+    },
+    /** 提交按钮 */
+    submitForm() {
+      this.$refs["form"].validate(valid => {
+        if (valid) {
+          if (this.form.id != null) {
+            updateProfile(this.form).then(response => {
+              if (response.code === 200) {
+                this.msgSuccess("修改成功");
+                this.open = false;
+                this.getList();
+              }
+            });
+          } else {
+            addProfile(this.form).then(response => {
+              if (response.code === 200) {
+                this.msgSuccess("新增成功");
+                this.open = false;
+                this.getList();
+              }
+            });
+          }
+        }
+      });
+    },
+    /** 删除按钮操作 */
+    handleDelete(row) {
+      const ids = row.id || this.ids;
+      this.$confirm('是否确认删除个人详情编号为"' + ids + '"的数据项?', "警告", {
+          confirmButtonText: "确定",
+          cancelButtonText: "取消",
+          type: "warning"
+        }).then(function() {
+          return delProfile(ids);
+        }).then(() => {
+          this.getList();
+          this.msgSuccess("删除成功");
+        }).catch(function() {});
+    },
+    /** 导出按钮操作 */
+    handleExport() {
+      const queryParams = this.queryParams;
+      this.$confirm('是否确认导出所有个人详情数据项?', "警告", {
+          confirmButtonText: "确定",
+          cancelButtonText: "取消",
+          type: "warning"
+        }).then(function() {
+          return exportProfile(queryParams);
+        }).then(response => {
+          this.download(response.msg);
+        }).catch(function() {});
+    },
+    
+    contentsFormat(row, column) {
+      var len = 28;
+      if(row.cotents.length >= len) {
+        return row.cotents.substr(0,len)+"...";
+      }
+      return row.cotents;
+    },
+    handleImg(row) {
+      this.$router.push({ 
+        path:'/user/profile/img',
+        query: {
+            pid: row.id
+        }
+      })
+    }
+  }
+};
+</script>

+ 9 - 4
src/views/system/appUser/index.vue

@@ -111,9 +111,9 @@
           <el-button
             size="mini"
             type="primary"
-            @click="myPage(scope.row)"
+            @click="myProfile(scope.row)"
             v-hasPermi="['system:appUser:query']"
-          >个人</el-button>
+          >个人详情</el-button>
           <el-button
             size="mini"
             type="danger"
@@ -475,8 +475,13 @@ export default {
         }).catch(function() {});
     }
     ,
-    myPage(row) {
-
+    myProfile(row) {
+      this.$router.push({ 
+        path:'/user/profiles',
+        query: {
+            uid: row.userId
+        }
+      })
     },
 
     myPublish(row) {