干燥机配套车间生产管理系统/云平台服务端
baoshiwei
2023-03-20 ec743754d4eec74005f64ed537989b5ba6af4e79
添加检测结果界面
已添加6个文件
已修改6个文件
735 ■■■■ 文件已修改
.env.development 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.env.production 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.env.test 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Dockerfile 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/dry/DryResultList.vue 173 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/dry/api/DryResult.api.ts 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/dry/components/DryResultForm.vue 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/dry/components/DryResultModal.vue 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/dry/dataDefine/DryOrder.data.ts 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/dry/dataDefine/DryResult.data.ts 181 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/dry/sql/DryResult_menu_insert.sql 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/system/depart/components/DepartRuleTab.vue 119 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.env.development
@@ -5,13 +5,13 @@
VITE_PUBLIC_PATH = /
# è·¨åŸŸä»£ç†ï¼Œæ‚¨å¯ä»¥é…ç½®å¤šä¸ª ,请注意,没有换行符
VITE_PROXY = [["/jeecgboot","http://192.168.21.70:9999"],["/upload","http://localhost:3300/upload"]]
VITE_PROXY = [["/herb","http://192.168.21.70:9999"],["/upload","http://localhost:3300/upload"]]
# æŽ§åˆ¶å°ä¸è¾“出
VITE_DROP_CONSOLE = false
#后台接口父地址(必填)
VITE_GLOB_API_URL=/jeecgboot
VITE_GLOB_API_URL=/herb
#后台接口全路径地址(必填)
VITE_GLOB_DOMAIN_URL=http://192.168.21.70:9999
.env.production
@@ -16,10 +16,10 @@
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false
#后台接口父地址(必填)
VITE_GLOB_API_URL=/jeecgboot
VITE_GLOB_API_URL=/herb
#后台接口全路径地址(必填)
VITE_GLOB_DOMAIN_URL=http://jeecg-boot-system:8080/jeecg-boot
VITE_GLOB_DOMAIN_URL=http://jeecg-boot-gateway:9999
# æŽ¥å£çˆ¶è·¯å¾„前缀
VITE_GLOB_API_URL_PREFIX=
.env.test
@@ -16,7 +16,7 @@
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false
#后台接口父地址(必填)
VITE_GLOB_API_URL=/jeecgboot
VITE_GLOB_API_URL=/herb
#后台接口全路径地址(必填)
VITE_GLOB_DOMAIN_URL=http://localhost:8080/jeecg-boot
Dockerfile
@@ -1,13 +1,13 @@
FROM nginx
MAINTAINER jeecgos@163.com
MAINTAINER bsw
VOLUME /tmp
ENV LANG en_US.UTF-8
RUN echo "server {  \
                      listen       80; \
                      location   /jeecgboot/ { \
                      proxy_pass              http://jeecg-boot-system:8080/jeecg-boot/; \
    location   /herb/ { \
    proxy_pass              http://jeecg-boot-gateway:9999/; \
                      proxy_redirect          off; \
                      proxy_set_header        Host jeecg-boot-system; \
    proxy_set_header        Host jeecg-boot-gateway; \
                      proxy_set_header        X-Real-IP \$remote_addr; \
                      proxy_set_header        X-Forwarded-For \$proxy_add_x_forwarded_for; \
                  } \
src/views/dry/DryResultList.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,173 @@
<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" :rowSelection="rowSelection">
     <!--插槽:table标题-->
      <template #tableTitle>
          <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> æ–°å¢ž</a-button>
          <a-button  type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> å¯¼å‡º</a-button>
          <j-upload-button  type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
          <a-dropdown v-if="selectedRowKeys.length > 0">
              <template #overlay>
                <a-menu>
                  <a-menu-item key="1" @click="batchHandleDelete">
                    <Icon icon="ant-design:delete-outlined"></Icon>
                    åˆ é™¤
                  </a-menu-item>
                </a-menu>
              </template>
              <a-button>批量操作
                <Icon icon="mdi:chevron-down"></Icon>
              </a-button>
        </a-dropdown>
      </template>
       <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </template>
      <!--字段回显插槽-->
      <template #htmlSlot="{text}">
         <div v-html="text"></div>
      </template>
      <!--省市区字段回显插槽-->
      <template #pcaSlot="{text}">
         {{ getAreaTextByCode(text) }}
      </template>
      <template #fileSlot="{text}">
         <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
         <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
      </template>
    </BasicTable>
    <!-- è¡¨å•区域 -->
    <DryResultModal @register="registerModal" @success="handleSuccess"></DryResultModal>
  </div>
</template>
<script lang="ts" name="dry-dryResult" setup>
  import {ref, computed, unref} from 'vue';
  import {BasicTable, useTable, TableAction} from '/@/components/Table';
  import {useModal} from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage'
  import DryResultModal from './components/DryResultModal.vue'
  import {columns, searchFormSchema} from './dataDefine/DryResult.data';
  import {list, deleteOne, batchDelete, getImportUrl,getExportUrl} from './api/DryResult.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  const checkedKeys = ref<Array<string | number>>([]);
  //注册model
  const [registerModal, {openModal}] = useModal();
  //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '测试结果',
           api: list,
           columns,
           canResize:false,
           formConfig: {
              //labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: {
               width: 120,
               fixed:'right'
            },
      },
       exportConfig: {
            name:"测试结果",
            url: getExportUrl,
          },
          importConfig: {
            url: getImportUrl,
            success: handleSuccess
          },
  })
  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext
   /**
    * æ–°å¢žäº‹ä»¶
    */
  function handleAdd() {
     openModal(true, {
       isUpdate: false,
       showFooter: true,
     });
  }
   /**
    * ç¼–辑事件
    */
  function handleEdit(record: Recordable) {
     openModal(true, {
       record,
       isUpdate: true,
       showFooter: true,
     });
   }
   /**
    * è¯¦æƒ…
   */
  function handleDetail(record: Recordable) {
     openModal(true, {
       record,
       isUpdate: true,
       showFooter: false,
     });
   }
   /**
    * åˆ é™¤äº‹ä»¶
    */
  async function handleDelete(record) {
     await deleteOne({id: record.id}, handleSuccess);
   }
   /**
    * æ‰¹é‡åˆ é™¤äº‹ä»¶
    */
  async function batchHandleDelete() {
     await batchDelete({ids: selectedRowKeys.value}, handleSuccess);
   }
   /**
    * æˆåŠŸå›žè°ƒ
    */
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }
   /**
      * æ“ä½œæ 
      */
  function getTableAction(record){
       return [
         {
           label: '编辑',
           onClick: handleEdit.bind(null, record),
         }
       ]
   }
     /**
        * ä¸‹æ‹‰æ“ä½œæ 
        */
  function getDropDownAction(record){
       return [
         {
           label: '详情',
           onClick: handleDetail.bind(null, record),
         }, {
           label: '删除',
           popConfirm: {
             title: '是否确认删除',
             confirm: handleDelete.bind(null, record),
           }
         }
       ]
   }
</script>
<style scoped>
</style>
src/views/dry/api/DryResult.api.ts
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,64 @@
import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";
const { createConfirm } = useMessage();
enum Api {
  list = '/dry/dryResult/list',
  save='/dry/dryResult/add',
  edit='/dry/dryResult/edit',
  deleteOne = '/dry/dryResult/delete',
  deleteBatch = '/dry/dryResult/deleteBatch',
  importExcel = '/dry/dryResult/importExcel',
  exportXls = '/dry/dryResult/exportXls',
}
/**
 * å¯¼å‡ºapi
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * å¯¼å…¥api
 */
export const getImportUrl = Api.importExcel;
/**
 * åˆ—表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});
/**
 * åˆ é™¤å•个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * æ‰¹é‡åˆ é™¤
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * ä¿å­˜æˆ–者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
src/views/dry/components/DryResultForm.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,70 @@
<template>
    <div style="min-height: 400px">
        <BasicForm @register="registerForm"></BasicForm>
        <div style="width: 100%;text-align: center" v-if="!formDisabled">
            <a-button @click="submitForm" pre-icon="ant-design:check" type="primary">提 äº¤</a-button>
        </div>
    </div>
</template>
<script lang="ts">
    import {BasicForm, useForm} from '/@/components/Form/index';
    import {computed, defineComponent} from 'vue';
    import {defHttp} from '/@/utils/http/axios';
    import { propTypes } from '/@/utils/propTypes';
    import {getBpmFormSchema} from '../dataDefine/DryResult.data';
    import {saveOrUpdate} from '../api/DryResult.api';
    export default defineComponent({
        name: "DryResultForm",
        components:{
            BasicForm
        },
        props:{
            formData: propTypes.object.def({}),
            formBpm: propTypes.bool.def(true),
        },
        setup(props){
            const [registerForm, { setFieldsValue, setProps, getFieldsValue }] = useForm({
                labelWidth: 150,
                schemas: getBpmFormSchema(props.formData),
                showActionButtonGroup: false,
                baseColProps: {span: 24}
            });
            const formDisabled = computed(()=>{
                if(props.formData.disabled === false){
                    return false;
                }
                return true;
            });
            let formData = {};
            const queryByIdUrl = '/dry/dryResult/queryById';
            async function initFormData(){
                let params = {id: props.formData.dataId};
                const data = await defHttp.get({url: queryByIdUrl, params});
                formData = {...data}
                //设置表单的值
                await setFieldsValue(formData);
                //默认是禁用
                await setProps({disabled: formDisabled.value})
            }
            async function submitForm() {
                let data = getFieldsValue();
                let params = Object.assign({}, formData, data);
                console.log('表单数据', params)
                await saveOrUpdate(params, true)
            }
            initFormData();
            return {
                registerForm,
                formDisabled,
                submitForm,
            }
        }
    });
</script>
src/views/dry/components/DryResultModal.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,66 @@
<template>
    <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit">
        <BasicForm @register="registerForm" />
    </BasicModal>
</template>
<script lang="ts" setup>
import { computed, ref, unref } from 'vue'
import { saveOrUpdate } from '../api/DryResult.api'
import { formSchema } from '../dataDefine/DryResult.data'
import { BasicForm, useForm } from '/@/components/Form/index'
import { BasicModal, useModalInner } from '/@/components/Modal'
// Emits声明
const emit = defineEmits(['register', 'success'])
const isUpdate = ref(true)
//表单配置
const [registerForm, { setProps, resetFields, setFieldsValue, validate }] = useForm({
    //labelWidth: 150,
    schemas: formSchema,
    showActionButtonGroup: false,
    baseColProps: { span: 24 },
})
//表单赋值
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    //重置表单
    await resetFields()
    setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter })
    isUpdate.value = !!data?.isUpdate
    if (unref(isUpdate)) {
        //表单赋值
        await setFieldsValue({
            ...data.record,
        })
    }
    // éšè—åº•部时禁用整个表单
    setProps({ disabled: !data?.showFooter })
})
//设置标题
const title = computed(() => (!unref(isUpdate) ? '新增' : '编辑'))
//表单提交事件
async function handleSubmit(v) {
    try {
        let values = await validate()
        setModalProps({ confirmLoading: true })
        //提交表单
        await saveOrUpdate(values, isUpdate.value)
        //关闭弹窗
        closeModal()
        //刷新列表
        emit('success')
    } finally {
        setModalProps({ confirmLoading: false })
    }
}
</script>
<style lang="less" scoped>
/** æ—¶é—´å’Œæ•°å­—输入框样式 */
:deep(.ant-input-number) {
    width: 100%;
}
:deep(.ant-calendar-picker) {
    width: 100%;
}
</style>
src/views/dry/dataDefine/DryOrder.data.ts
@@ -79,7 +79,23 @@
  },
]
//查询数据
export const searchFormSchema: FormSchema[] = []
export const searchFormSchema: FormSchema[] = [
    {
        label: '工单时间',
        field: 'orderTime',
        component: 'RangePicker',
        componentProps: {
            valueType: 'Date',
        },
        colProps: { span: 6 },
    },
    {
        label: '药材名称',
        field: 'herbName',
        component: 'Input',
        colProps: { span: 6 },
    },
]
//表单数据
export const formSchema: FormSchema[] = [
  {
src/views/dry/dataDefine/DryResult.data.ts
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,181 @@
import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '药材名称',
    align:"center",
    dataIndex: 'herbName'
   },
   {
    title: '装料量',
    align:"center",
    dataIndex: 'feed'
   },
   {
    title: '初始重量',
    align:"center",
    dataIndex: 'weight'
   },
   {
    title: '目标水分',
    align:"center",
    dataIndex: 'target'
   },
   {
    title: '工单号',
    align:"center",
    dataIndex: 'orderNo'
   },
   {
    title: '工单id',
    align:"center",
    dataIndex: 'orderId'
   },
   {
    title: '前左',
    align:"center",
    dataIndex: 'frontLeft'
   },
   {
    title: '前左',
    align:"center",
    dataIndex: 'frontRight'
   },
   {
    title: '中左',
    align:"center",
    dataIndex: 'middleLeft'
   },
   {
    title: '中右',
    align:"center",
    dataIndex: 'middleRight'
   },
   {
    title: '后左',
    align:"center",
    dataIndex: 'backLeft'
   },
   {
    title: '后右',
    align:"center",
    dataIndex: 'backRight'
   },
   {
    title: '平均',
    align:"center",
    dataIndex: 'avg'
   },
   {
    title: '时长',
    align:"center",
    dataIndex: 'dryTime'
   },
   {
    title: '蒸汽(立方)',
    align:"center",
    dataIndex: 'steam'
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '药材名称',
    field: 'herbName',
    component: 'Input',
  },
  {
    label: '装料量',
    field: 'feed',
    component: 'InputNumber',
  },
  {
    label: '初始重量',
    field: 'weight',
    component: 'InputNumber',
  },
  {
    label: '目标水分',
    field: 'target',
    component: 'InputNumber',
  },
  {
    label: '工单号',
    field: 'orderNo',
    component: 'Input',
  },
  {
    label: '工单id',
    field: 'orderId',
    component: 'Input',
  },
  {
    label: '前左',
    field: 'frontLeft',
    component: 'InputNumber',
  },
  {
    label: '前左',
    field: 'frontRight',
    component: 'InputNumber',
  },
  {
    label: '中左',
    field: 'middleLeft',
    component: 'InputNumber',
  },
  {
    label: '中右',
    field: 'middleRight',
    component: 'InputNumber',
  },
  {
    label: '后左',
    field: 'backLeft',
    component: 'InputNumber',
  },
  {
    label: '后右',
    field: 'backRight',
    component: 'InputNumber',
  },
  {
    label: '平均',
    field: 'avg',
    component: 'InputNumber',
  },
  {
    label: '时长',
    field: 'dryTime',
    component: 'InputNumber',
  },
  {
    label: '蒸汽(立方)',
    field: 'steam',
    component: 'InputNumber',
  },
    // TODO ä¸»é”®éšè—å­—段,目前写死为ID
    {
      label: '',
      field: 'id',
      component: 'Input',
      show: false
    },
];
/**
* æµç¨‹è¡¨å•调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // é»˜è®¤å’ŒåŽŸå§‹è¡¨å•ä¿æŒä¸€è‡´ å¦‚果流程中配置了权限数据,这里需要单独处理formSchema
  return formSchema;
}
src/views/dry/sql/DryResult_menu_insert.sql
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,26 @@
-- æ³¨æ„ï¼šè¯¥é¡µé¢å¯¹åº”的前台目录为views/dry文件夹下
-- å¦‚果你想更改到其他目录,请修改sql中component字段对应的值
INSERT INTO sys_permission(id, parent_id, name, url, component, component_name, redirect, menu_type, perms, perms_type, sort_no, always_show, icon, is_route, is_leaf, keep_alive, hidden, hide_tab, description, status, del_flag, rule_flag, create_by, create_time, update_by, update_time, internal_or_external)
VALUES ('2023031902327130210', NULL, '测试结果', '/dry/dryResultList', 'dry/DryResultList', NULL, NULL, 0, NULL, '1', 0.00, 0, NULL, 1, 0, 0, 0, 0, NULL, '1', 0, 0, 'admin', '2023-03-19 14:32:21', NULL, NULL, 0);
-- æƒé™æŽ§åˆ¶sql
-- æ–°å¢ž
INSERT INTO sys_permission(id, parent_id, name, url, component, is_route, component_name, redirect, menu_type, perms, perms_type, sort_no, always_show, icon, is_leaf, keep_alive, hidden, hide_tab, description, create_by, create_time, update_by, update_time, del_flag, rule_flag, status, internal_or_external)
VALUES ('2023031902327140211', '2023031902327130210', '添加测试结果', NULL, NULL, 0, NULL, NULL, 2, 'dry:dry_result:add', '1', NULL, 0, NULL, 1, 0, 0, 0, NULL, 'admin', '2023-03-19 14:32:21', NULL, NULL, 0, 0, '1', 0);
-- ç¼–辑
INSERT INTO sys_permission(id, parent_id, name, url, component, is_route, component_name, redirect, menu_type, perms, perms_type, sort_no, always_show, icon, is_leaf, keep_alive, hidden, hide_tab, description, create_by, create_time, update_by, update_time, del_flag, rule_flag, status, internal_or_external)
VALUES ('2023031902327140212', '2023031902327130210', '编辑测试结果', NULL, NULL, 0, NULL, NULL, 2, 'dry:dry_result:edit', '1', NULL, 0, NULL, 1, 0, 0, 0, NULL, 'admin', '2023-03-19 14:32:21', NULL, NULL, 0, 0, '1', 0);
-- åˆ é™¤
INSERT INTO sys_permission(id, parent_id, name, url, component, is_route, component_name, redirect, menu_type, perms, perms_type, sort_no, always_show, icon, is_leaf, keep_alive, hidden, hide_tab, description, create_by, create_time, update_by, update_time, del_flag, rule_flag, status, internal_or_external)
VALUES ('2023031902327140213', '2023031902327130210', '删除测试结果', NULL, NULL, 0, NULL, NULL, 2, 'dry:dry_result:delete', '1', NULL, 0, NULL, 1, 0, 0, 0, NULL, 'admin', '2023-03-19 14:32:21', NULL, NULL, 0, 0, '1', 0);
-- æ‰¹é‡åˆ é™¤
INSERT INTO sys_permission(id, parent_id, name, url, component, is_route, component_name, redirect, menu_type, perms, perms_type, sort_no, always_show, icon, is_leaf, keep_alive, hidden, hide_tab, description, create_by, create_time, update_by, update_time, del_flag, rule_flag, status, internal_or_external)
VALUES ('2023031902327140214', '2023031902327130210', '批量删除测试结果', NULL, NULL, 0, NULL, NULL, 2, 'dry:dry_result:deleteBatch', '1', NULL, 0, NULL, 1, 0, 0, 0, NULL, 'admin', '2023-03-19 14:32:21', NULL, NULL, 0, 0, '1', 0);
-- å¯¼å‡ºexcel
INSERT INTO sys_permission(id, parent_id, name, url, component, is_route, component_name, redirect, menu_type, perms, perms_type, sort_no, always_show, icon, is_leaf, keep_alive, hidden, hide_tab, description, create_by, create_time, update_by, update_time, del_flag, rule_flag, status, internal_or_external)
VALUES ('2023031902327140215', '2023031902327130210', '导出excel_测试结果', NULL, NULL, 0, NULL, NULL, 2, 'dry:dry_result:exportXls', '1', NULL, 0, NULL, 1, 0, 0, 0, NULL, 'admin', '2023-03-19 14:32:21', NULL, NULL, 0, 0, '1', 0);
-- å¯¼å…¥excel
INSERT INTO sys_permission(id, parent_id, name, url, component, is_route, component_name, redirect, menu_type, perms, perms_type, sort_no, always_show, icon, is_leaf, keep_alive, hidden, hide_tab, description, create_by, create_time, update_by, update_time, del_flag, rule_flag, status, internal_or_external)
VALUES ('2023031902327140216', '2023031902327130210', '导入excel_测试结果', NULL, NULL, 0, NULL, NULL, 2, 'dry:dry_result:importExcel', '1', NULL, 0, NULL, 1, 0, 0, 0, NULL, 'admin', '2023-03-19 14:32:21', NULL, NULL, 0, 0, '1', 0);
src/views/system/depart/components/DepartRuleTab.vue
@@ -1,20 +1,9 @@
<template>
  <a-spin :spinning="loading">
    <template v-if="treeData.length > 0">
      <BasicTree
        ref="basicTree"
        class="depart-rule-tree"
        checkable
        :treeData="treeData"
        :checkedKeys="checkedKeys"
        :selectedKeys="selectedKeys"
        :expandedKeys="expandedKeys"
        :checkStrictly="checkStrictly"
        style="height: 500px; overflow: auto"
        @check="onCheck"
        @expand="onExpand"
        @select="onSelect"
      >
      <BasicTree ref="basicTree" class="depart-rule-tree" checkable :treeData="treeData" :checkedKeys="checkedKeys"
        :selectedKeys="selectedKeys" :expandedKeys="expandedKeys" :checkStrictly="checkStrictly"
        style="height: 500px; overflow: auto" @check="onCheck" @expand="onExpand" @select="onSelect">
        <template #title="{ slotTitle, ruleFlag }">
          <span>{{ slotTitle }}</span>
          <Icon v-if="ruleFlag" icon="ant-design:align-left-outlined" style="margin-left: 5px; color: red" />
@@ -28,6 +17,8 @@
        <a-dropdown :trigger="['click']" placement="top">
          <template #overlay>
            <a-menu>
              <a-menu-item key="1" @click="toggleCheckStrictly(false)">父子关联</a-menu-item>
              <a-menu-item key="2" @click="toggleCheckStrictly(true)">取消关联</a-menu-item>
              <a-menu-item key="3" @click="toggleCheckALL(true)">全部勾选</a-menu-item>
              <a-menu-item key="4" @click="toggleCheckALL(false)">取消全选</a-menu-item>
              <a-menu-item key="5" @click="toggleExpandAll(true)">展开所有</a-menu-item>
@@ -47,117 +38,117 @@
</template>
<script lang="ts" setup>
  import { watch, computed, inject, ref, nextTick } from 'vue';
  import { useDrawer } from '/@/components/Drawer';
  import { BasicTree } from '/@/components/Tree/index';
  import DepartDataRuleDrawer from './DepartDataRuleDrawer.vue';
  import { queryRoleTreeList, queryDepartPermission, saveDepartPermission } from '../depart.api';
import { computed, inject, nextTick, ref, watch } from 'vue'
import { queryDepartPermission, queryRoleTreeList, saveDepartPermission } from '../depart.api'
import DepartDataRuleDrawer from './DepartDataRuleDrawer.vue'
import { useDrawer } from '/@/components/Drawer'
import { BasicTree } from '/@/components/Tree/index'
  const props = defineProps({
    data: { type: Object, default: () => ({}) },
  });
})
  // å½“前选中的部门ID,可能会为空,代表未选择部门
  const departId = computed(() => props.data?.id);
const departId = computed(() => props.data?.id)
  const prefixCls = inject('prefixCls');
  const basicTree = ref();
  const loading = ref<boolean>(false);
  const treeData = ref<any[]>([]);
  const expandedKeys = ref<Array<any>>([]);
  const selectedKeys = ref<Array<any>>([]);
  const checkedKeys = ref<Array<any>>([]);
  const lastCheckedKeys = ref<Array<any>>([]);
  const checkStrictly = ref(true);
const prefixCls = inject('prefixCls')
const basicTree = ref()
const loading = ref<boolean>(false)
const treeData = ref<any[]>([])
const expandedKeys = ref<Array<any>>([])
const selectedKeys = ref<Array<any>>([])
const checkedKeys = ref<Array<any>>([])
const lastCheckedKeys = ref<Array<any>>([])
const checkStrictly = ref(true)
  // æ³¨å†Œæ•°æ®è§„则授权弹窗抽屉
  const [registerDataRuleDrawer, dataRuleDrawer] = useDrawer();
const [registerDataRuleDrawer, dataRuleDrawer] = useDrawer()
  // onCreated
  loadData();
  watch(departId, () => loadDepartPermission(), { immediate: true });
loadData()
watch(departId, () => loadDepartPermission(), { immediate: true })
  async function loadData() {
    try {
      loading.value = true;
      let { treeList } = await queryRoleTreeList();
      treeData.value = treeList;
      await nextTick();
      toggleExpandAll(true);
    loading.value = true
    let { treeList } = await queryRoleTreeList()
    treeData.value = treeList
    await nextTick()
    toggleExpandAll(true)
    } finally {
      loading.value = false;
    loading.value = false
    }
  }
  async function loadDepartPermission() {
    if (departId.value) {
      try {
        loading.value = true;
        let keys = await queryDepartPermission({ departId: departId.value });
        checkedKeys.value = keys;
        lastCheckedKeys.value = [...keys];
      loading.value = true
      let keys = await queryDepartPermission({ departId: departId.value })
      checkedKeys.value = keys
      lastCheckedKeys.value = [...keys]
      } finally {
        loading.value = false;
      loading.value = false
      }
    }
  }
  async function onSubmit() {
    try {
      loading.value = true;
    loading.value = true
      await saveDepartPermission({
        departId: departId.value,
        permissionIds: checkedKeys.value.join(','),
        lastpermissionIds: lastCheckedKeys.value.join(','),
      });
      await loadData();
      await loadDepartPermission();
    })
    await loadData()
    await loadDepartPermission()
    } finally {
      loading.value = false;
    loading.value = false
    }
  }
  // tree勾选复选框事件
  function onCheck(event) {
    if (!Array.isArray(event)) {
      checkedKeys.value = event.checked;
    checkedKeys.value = event.checked
    } else {
      checkedKeys.value = event;
    checkedKeys.value = event
    }
  }
  // tree展开事件
  function onExpand($expandedKeys) {
    expandedKeys.value = $expandedKeys;
  expandedKeys.value = $expandedKeys
  }
  // tree选中事件
  function onSelect($selectedKeys, { selectedNodes }) {
    if (selectedNodes[0]?.ruleFlag) {
      let functionId = $selectedKeys[0];
      dataRuleDrawer.openDrawer(true, { departId, functionId });
    let functionId = $selectedKeys[0]
    dataRuleDrawer.openDrawer(true, { departId, functionId })
    }
    selectedKeys.value = [];
  selectedKeys.value = []
  }
  // åˆ‡æ¢çˆ¶å­å…³è”
  async function toggleCheckStrictly(flag) {
    checkStrictly.value = flag;
    await nextTick();
    checkedKeys.value = basicTree.value.getCheckedKeys();
  checkStrictly.value = flag
  await nextTick()
  checkedKeys.value = basicTree.value.getCheckedKeys()
  }
  // åˆ‡æ¢å±•开收起
  async function toggleExpandAll(flag) {
    basicTree.value.expandAll(flag);
    await nextTick();
    expandedKeys.value = basicTree.value.getExpandedKeys();
  basicTree.value.expandAll(flag)
  await nextTick()
  expandedKeys.value = basicTree.value.getExpandedKeys()
  }
  // åˆ‡æ¢å…¨é€‰
  async function toggleCheckALL(flag) {
    basicTree.value.checkAll(flag);
    await nextTick();
    checkedKeys.value = basicTree.value.getCheckedKeys();
  basicTree.value.checkAll(flag)
  await nextTick()
  checkedKeys.value = basicTree.value.getCheckedKeys()
  }
</script>