123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766 |
- <!--
- * @Author : yuanrunwei
- * @Date : 2021-12-04 14:23:58
- * @LastEditors: Please set LastEditors
- * @LastEditTime: 2022-01-10 20:43:30
- * @FilePath : \spfm-market-front\src\pages\main\performance\components\sheet.vue
- -->
- <template>
- <div class="sheet-container">
- <div class="flex-justify-align-end margin-bottom-20">
- <el-button
- type="primary"
- @click="handleVisible"
- v-if="['template'].includes(attribute)"
- >权限设置</el-button
- >
- <el-button type="primary" @click="handleDownload">导出</el-button>
- <el-button type="primary" @click="handleFullscreen()">全屏显示</el-button>
- <template v-if="['edit'].includes(type)">
- <el-upload
- v-if="!id"
- class="margin-right-10 margin-left-10"
- action
- :on-change="handleChange"
- :show-file-list="false"
- >
- <el-button type="primary">上传</el-button>
- </el-upload>
- <el-button
- v-if="addFlag === '0'"
- type="primary"
- @click="handleSave"
- :disabled="handleForbid()"
- ><span>{{ id ? "提交" : "新增" }}</span
- ><span>{{
- handleForbid() ? `(请先设置权限)` : ""
- }}</span></el-button
- >
- </template>
- </div>
- <div id="luckysheet" class="sheet-container-block"></div>
- <simple-dialog
- title="权限设置"
- :visible="visible"
- :modal="false"
- width="1400px"
- @confirm="handleAuth"
- @cancel="handleVisible"
- >
- <el-form ref="form" :model="form" label-width="80px">
- <el-radio-group v-model="form.permission_type">
- <el-form-item>
- <el-radio :label="0"><span>无特殊权限</span></el-radio>
- <div>
- <span class="form-content">负责人</span>
- <el-select
- v-model="form.person"
- multiple
- placeholder="请选择负责人"
- >
- <el-option
- v-for="({ label, value }, index) in charge_list"
- :key="index"
- :label="label"
- :value="value"
- ></el-option>
- </el-select>
- </div>
- <!-- <div class="form-input">
- <span class="form-content"> 可编辑行:从</span>
- <el-input v-model="form.col_start" />
- <span class="form-content">到</span
- ><el-input v-model="form.col_end" />
- </div>
- <div class="form-input">
- <span class="form-content">可编辑列:从</span>
- <el-input v-model="form.row_start" />
- <span class="form-content">到</span>
- <el-input v-model="form.row_end" />
- </div> -->
- </el-form-item>
- <el-form-item>
- <el-radio :label="1"><span>特殊权限:</span></el-radio>
- <el-form-item
- label="负责人"
- prop="charge"
- v-for="(item, index) in form.charge"
- :key="index"
- :rules="{
- required: true,
- message: '负责人不能为空',
- trigger: 'blur',
- }"
- >
- <div class="flex">
- <el-select
- class="margin-bottom-20 margin-right-10"
- placeholder="请选择负责人"
- v-model="item.person"
- filterable
- >
- <el-option
- v-for="({ label, value }, index) in charge_list"
- :key="index"
- :label="label"
- :value="value"
- ></el-option>
- </el-select>
- <div class="form-select">
- <span class="form-content">可编辑行:从</span>
- <el-input v-model="item.col_start" />
- <span class="form-content">到</span>
- <el-input v-model="item.col_end" />
- </div>
- <div class="form-select">
- <span class="form-content">可编辑列:从</span>
- <el-input v-model="item.row_start" />
- <span class="form-content">到</span>
- <el-input v-model="item.row_end" />
- </div>
- </div>
- </el-form-item>
- <div>
- <el-button @click.prevent="handleCharge('add')">添加</el-button>
- <el-button
- v-if="form.charge.length - 1"
- @click.prevent="handleCharge('delete')"
- >删除</el-button
- >
- </div>
- </el-form-item>
- </el-radio-group>
- <!-- <el-form-item
- label="可编辑列"
- prop="array"
- ><el-select
- v-model="form.array"
- placeholder="可编辑列"
- multiple
- >
- <el-option
- v-for="(value, index) in 10"
- :key="index"
- :label="index + 1"
- :value="index + 1"
- >
- </el-option> </el-select
- ></el-form-item>
- <el-form-item
- label="权限规则"
- prop="type"
- :rules="{
- required: true,
- message: '权限规则不能为空',
- trigger: 'change',
- }"
- >
- <el-select v-model="form.type">
- <el-option
- v-for="item in type_options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- ></el-option> </el-select
- ></el-form-item>
- <el-form-item
- label="负责人"
- prop="charge"
- :rules="{
- required: true,
- message: '负责人不能为空',
- trigger: 'blur',
- }"
- >
- <div
- class="flex-justify-start"
- v-for="(item, index) in form.charge"
- :key="index"
- >
- <el-select
- v-model="item.key"
- class="margin-bottom-20 margin-right-10 flex-1"
- placeholder="请选择指定列/行"
- multiple
- >
- <el-option
- v-for="(value, index) in 10"
- :key="index"
- :label="index + 1"
- :value="index + 1"
- >
- </el-option>
- </el-select>
- <el-select
- class="margin-bottom-20"
- placeholder="请选择负责人"
- v-model="item.value"
- filterable
- >
- <el-option
- v-for="({ label, value }, index) in charge_list"
- :key="index"
- :label="label"
- :value="value"
- ></el-option>
- </el-select>
- </div>
- <div>
- <el-button @click.prevent="handleCharge('add')"
- >添加</el-button
- >
- <el-button
- v-if="form.charge.length - 1"
- @click.prevent="handleCharge('delete')"
- >删除</el-button
- >
- </div>
- </el-form-item> -->
- </el-form>
- <template v-if="id" v-slot:footer><div></div></template>
- </simple-dialog>
- </div>
- </template>
- <script>
- import luckyexcel from "luckyexcel";
- import { exportExcel } from "../common/export";
- import simpleDialog from "./dialog.vue";
- export default {
- components: {
- simpleDialog,
- },
- props: {
- type: {
- type: String,
- default: "view", // view 查看 edit 编辑
- },
- attribute: {
- type: String,
- default: "template", // template 模板 order 工单 file 文件
- },
- id: {
- default: null,
- },
- },
- data() {
- return {
- form: {
- charge: [
- {
- person: [],
- col_start: "",
- col_end: "",
- row_start: "",
- row_end: "",
- },
- ],
- array: [],
- type: null,
- permission_type: null,
- col_start: "",
- col_end: "",
- row_start: "",
- row_end: "",
- },
- // 可提交标志
- addFlag: null,
- isDisable: true,
- issued_id: null,
- template_id: null,
- visible: false,
- row_list: [],
- column_list: [],
- charge_list: [],
- type_options: [
- {
- value: 1,
- label: "按行",
- },
- // {
- // value: 2,
- // label: "按列",
- // },
- ],
- };
- },
- methods: {
- handleInit() {
- if (this.id) {
- this.handleQuery();
- } else {
- this.handleCreate();
- }
- },
- // // 权限选择
- // handleRadio(e){
- // console.log(e,'e');
- // },
- handleAllow({ row, column }) {
- return (
- (!this.form.permission_type && this.type === "edit") ||
- (this.row_list.includes(row) && this.column_list.includes(column))
- );
- },
- async handleQuery() {
- let url = "";
- let key = "";
- switch (this.attribute) {
- case "template":
- url = "/market/CMKFileTemplate/QueryCMKFileTemplateById";
- key = "templateId";
- break;
- case "order":
- url = "/market/CMKIssued/CMKQueryIssuedById";
- key = "id";
- break;
- case "file":
- url = "/market/CMKIssued/CMKIssuedProcessByUser";
- key = "id";
- break;
- }
- const {
- data: {
- templateContent,
- templateName,
- issuedId,
- templateId,
- list,
- addFlag,
- },
- } = await this.$http({
- url,
- method: "post",
- headers: {
- "Content-Type": "application/json",
- },
- data: {
- [key]: this.id,
- },
- });
- this.template_id = templateId;
- this.issued_id = issuedId;
- this.addFlag = addFlag;
- console.log(addFlag, "addFlag");
- if (list && list.length) {
- const { type } = list[0];
- if (type === "1") {
- // 公共权限
- // const { allowEditingColumns, rowNum } = list[0];
- this.form = {
- permission_type: Number(type) - 1,
- person: list.map((el) => {
- return `${el.principalId},${el.principalName}`;
- }),
- charge: [
- {
- person: "",
- col_start: "",
- col_end: "",
- row_start: "",
- row_end: "",
- },
- ],
- };
- } else {
- // 特殊权限
- this.form = {
- permission_type: Number(type) - 1,
- col_start: "",
- col_end: "",
- row_start: "",
- row_end: "",
- charge: list.map((el) => ({
- person: el.principalId + "," + el.principalName,
- col_start: el.allowEditingColumns.split(",")[0],
- col_end:
- el.allowEditingColumns.split(",")[
- el.allowEditingColumns.split(",").length - 1
- ],
- row_start: el.rowNum.split(",")[0],
- row_end: el.rowNum.split(",")[el.rowNum.split(",").length - 1],
- })),
- };
- }
- // this.form = {
- // ...this.form,
- // type: type,
- // array: allowEditingColumns ? allowEditingColumns.split(",") : [],
- // charge: list.map(({ principalId, principalName, rowNum }) => ({
- // value: `${principalId},${principalName}`,
- // key: rowNum.split(","),
- // })),
- // };
- // this.form = {};
- this.row_list =
- this.type === "edit" && list[0].rowNum
- ? list[0].rowNum
- .split(",")
- .map((element) => JSON.parse(element) - 1)
- : [];
- this.column_list =
- this.type === "edit" && list[0].allowEditingColumns
- ? list[0].allowEditingColumns
- .split(",")
- .map((element) => JSON.parse(element) - 1)
- : [];
- }
- this.handleCreate({
- json: templateContent ? JSON.parse(templateContent) : {},
- name: templateName,
- type: "json",
- });
- },
- handleForbid() {
- // const object = {};
- const { permission_type } = this.form;
- if (permission_type === 0) {
- // 公共权限 暂时不用可编辑行和列
- const { person } = this.form;
- if (person.length) {
- return false;
- }
- return true;
- } else if (permission_type === 1) {
- // 特殊权限
- let flag = 1;
- const { charge } = this.form;
- charge.forEach((el) => {
- if (
- Object.values(el).filter((v) => {
- return v !== "";
- }).length === 5
- ) {
- flag = flag * 1;
- } else {
- flag = flag * 0;
- }
- });
- return !flag;
- } else {
- return true;
- }
- // form: {
- // charge: [
- // {
- // person: "",
- // col_start: "",
- // col_End: "",
- // row_start: "",
- // row_end: "",
- // },
- // ],
- // array: [],
- // type: null,
- // permission_type: 0,
- // col_start: "",
- // col_end: "",
- // row_start: "",
- // row_end: "",
- // },
- // charge.map(({ key }) => {
- // console.log(key);
- // // if (key && value) {
- // // object[key] = value;
- // // }
- // });
- // return !(Object.keys(object).length && type);
- },
- async handleCreate({ file, json, type, name } = {}) {
- let that = this;
- const options = {
- container: "luckysheet",
- lang: "zh",
- showsheetbar: false,
- hook: {
- cellEditBefore: function ([
- { row_focus: row, column_focus: column },
- ]) {
- if (!that.handleAllow({ row, column })) {
- that.$message.error("您没有编辑权限");
- }
- },
- cellUpdateBefore: function (row, column) {
- if (!that.handleAllow({ row, column })) {
- return false;
- }
- },
- cellRenderAfter: function (cell, position) {
- const { r: row, c: column } = position;
- if (cell) {
- if (!that.handleAllow({ row, column })) {
- cell.bg = "#d5d5d5";
- } else {
- cell.bg = "#ffffff";
- }
- }
- },
- },
- };
- switch (type) {
- case "file":
- if (file) {
- await new Promise((resolve) => {
- luckyexcel.transformExcelToLucky(file, (export_json) => {
- options.data = [
- ...export_json.sheets.map((element) => ({
- ...element,
- zoomRatio: 0.75,
- })),
- ];
- options.title = export_json.info.name;
- resolve();
- });
- });
- }
- break;
- case "json":
- if (json) {
- options.data = [
- {
- ...json,
- zoomRatio: 0.75,
- },
- ];
- options.title = name;
- }
- break;
- }
- window.luckysheet.create(options);
- let clock = setInterval(() => {
- if (window.luckysheet) {
- window.luckysheet.refresh();
- clearInterval(clock);
- }
- }, 1000);
- },
- async handleChange(response) {
- this.handleCreate({ file: response.raw, type: "file" });
- },
- handleDownload() {
- exportExcel(
- window.luckysheet.getAllSheets(),
- window.luckysheet.getWorkbookName()
- );
- },
- async handleAddAuth({ id }) {
- // const object = {};
- const { permission_type } = this.form;
- console.log(id, permission_type);
- let reqdata = {
- templateId: id,
- type: permission_type ? 2 : 1,
- };
- if (!permission_type) {
- // 公共权限
- const { person } = this.form;
- const principalId = [];
- const principalName = [];
- person.forEach((el) => {
- principalId.push(el.split(",")[0]);
- principalName.push(el.split(",")[1]);
- });
- reqdata.principalId = principalId.join(",");
- reqdata.principalName = principalName.join(",");
- } else {
- const { charge } = this.form;
- // 特殊权限
- reqdata.specialAuth = charge.map((el) =>
- JSON.stringify({
- allowEditingColumns: this.paramsArr(el.col_start, el.col_end),
- rowNum: this.paramsArr(el.row_start, el.row_end),
- principalId: el.person.split(",")[0],
- principalName: el.person.split(",")[1],
- })
- );
- }
- await this.$http({
- url: this.id
- ? "/market/CMKFileTemplateAuthority/CMKFileTemplateAuthorityUpdate"
- : "/market/CMKFileTemplateAuthority/CMKFileTemplateAuthorityAdd",
- method: "post",
- headers: {
- "Content-Type": "application/json",
- },
- data: reqdata,
- });
- this.$message.success("操作成功");
- },
- async handleSave() {
- let edit_url = "";
- switch (this.attribute) {
- case "template":
- edit_url = "";
- break;
- case "order":
- edit_url = "";
- break;
- case "file":
- edit_url = "/market/CMKIssued/CMKIssuedSubmit";
- break;
- }
- const sheet_name = window.luckysheet.getSheet().name;
- const data = window.luckysheet.getSheet(sheet_name);
- const workbook_name = window.luckysheet.getWorkbookName();
- const {
- data: { body },
- } = await this.$http({
- url: this.id
- ? edit_url // 编辑
- : "/market/CMKFileTemplate/CMKFileTemplateAdd", // 新增
- method: "post",
- headers: {
- "Content-Type": "application/json",
- },
- data: {
- id: this.template_id,
- templateContent: JSON.stringify(data),
- templateName: workbook_name,
- issuedId: this.issued_id,
- },
- });
- // 新增时添加权限
- if (!this.id) {
- this.handleAddAuth({ id: body });
- } else {
- this.$message.success("提交成功");
- }
- this.$emit("save");
- },
- handleAuth() {
- this.$refs["form"].validate((valid) => {
- if (valid) {
- if (this.handleForbid()) {
- this.$message.error("请完善可编辑信息");
- return false;
- }
- this.handleVisible();
- if (this.id) {
- this.handleAddAuth({ id: this.id });
- } else {
- this.$message.success("设置成功");
- }
- }
- });
- },
- // 通用方法用于转化全局
- paramsArr(start, end) {
- const arr = [];
- console.log(start, end);
- for (let i = Number(start); i <= Number(end); i++) {
- arr.push(i);
- }
- return arr.join(",");
- },
- filterName(id, arr) {
- return arr.filter((el) => el.secLeaderLogin === id)[0].secLeaderName;
- },
- handleCharge(type) {
- switch (type) {
- case "add":
- this.form.charge.push({
- person: "",
- });
- this.handleForbid();
- break;
- case "delete":
- this.form.charge.pop();
- this.handleForbid();
- break;
- }
- },
- handleVisible() {
- console.log(this.form, "aada");
- this.visible = !this.visible;
- },
- handleFullscreen() {
- const element = document.body;
- const is_fullscreen =
- document.fullScreen ||
- document.mozFullScreen ||
- document.webkitIsFullScreen;
- if (!is_fullscreen) {
- //进入全屏,多重短路表达式
- (element.requestFullscreen && element.requestFullscreen()) ||
- (element.mozRequestFullScreen && element.mozRequestFullScreen()) ||
- (element.webkitRequestFullscreen &&
- element.webkitRequestFullscreen()) ||
- (element.msRequestFullscreen && element.msRequestFullscreen());
- } else {
- //退出全屏,三目运算符
- document.exitFullscreen
- ? document.exitFullscreen()
- : document.mozCancelFullScreen
- ? document.mozCancelFullScreen()
- : document.webkitExitFullscreen
- ? document.webkitExitFullscreen()
- : "";
- }
- },
- handleChargeList() {
- this.$http({
- url: "/market/techcentergj/queryLeaderList",
- method: "post",
- headers: {
- "Content-Type": "application/json",
- },
- data: {},
- }).then((response) => {
- this.charge_list = response.data.map((element) => ({
- label: `${element.ou} ${element.secLeaderName}`,
- value: `${element.secLeaderLogin},${element.secLeaderName}`,
- }));
- });
- },
- },
- mounted() {
- this.handleInit();
- this.handleChargeList();
- },
- };
- </script>
- <style lang="scss" scope>
- .sheet-container {
- position: fixed;
- width: calc(100% - 40px);
- height: 100%;
- &-block {
- overflow: hidden;
- position: absolute;
- width: 100%;
- height: 75%;
- }
- }
- .form {
- &-input {
- margin-top: 5px;
- .el-input {
- width: 150px;
- .el-input__inner {
- height: 30px !important;
- line-height: 30px !important;
- }
- }
- }
- &-content {
- margin: 0px 10px;
- }
- &-select {
- .el-input {
- width: 100px;
- .el-input__inner {
- height: 30px !important;
- line-height: 30px !important;
- }
- }
- }
- }
- </style>
|