ezhizao_zx 4 months ago
parent
commit
568646ffdd
5 changed files with 160 additions and 39 deletions
  1. 84 6
      src/layout/components/Navbar.vue
  2. 6 2
      src/permission.js
  3. 17 1
      src/store/modules/settings.js
  4. 38 18
      src/utils/request.js
  5. 15 12
      src/views/index.vue

+ 84 - 6
src/layout/components/Navbar.vue

@@ -45,11 +45,13 @@
               <el-dropdown-item command="setLayout">
               <el-dropdown-item command="setLayout">
                 <span>布局设置</span>
                 <span>布局设置</span>
               </el-dropdown-item>
               </el-dropdown-item>
-              <el-dropdown-item command="message">
+              <el-dropdown-item command="message" v-if="settingsStore.showMessage">
                 <el-badge :value="messageCount" :max="99" class="item" :hidden="messageCount == 0">
                 <el-badge :value="messageCount" :max="99" class="item" :hidden="messageCount == 0">
                   <span>站内信</span>
                   <span>站内信</span>
                 </el-badge>
                 </el-badge>
-
+              </el-dropdown-item>
+              <el-dropdown-item command="sendMessage" v-if="settingsStore.showMessage">
+                <span>发站内信</span>
               </el-dropdown-item>
               </el-dropdown-item>
               <el-dropdown-item divided command="logout">
               <el-dropdown-item divided command="logout">
                 <span>退出登录</span>
                 <span>退出登录</span>
@@ -76,7 +78,7 @@
         <el-table ref="dialogTable" :data="messageList" height="460px" row-key="id" align="center">
         <el-table ref="dialogTable" :data="messageList" height="460px" row-key="id" align="center">
           <el-table-column label="行号" type="index" width="50" align="center" />
           <el-table-column label="行号" type="index" width="50" align="center" />
           <el-table-column label="消息来源" prop="fromNickName" align="center" />
           <el-table-column label="消息来源" prop="fromNickName" align="center" />
-          <el-table-column label="消息内容" prop="message" align="center" />
+          <el-table-column label="消息内容" prop="message" align="center" show-overflow-tooltip />
           <el-table-column label="查看" width="120" align="center">
           <el-table-column label="查看" width="120" align="center">
             <template #default="scope">
             <template #default="scope">
               <el-button type="success" icon="view" circle @click="handleView(scope.row)" />
               <el-button type="success" icon="view" circle @click="handleView(scope.row)" />
@@ -85,9 +87,43 @@
         </el-table>
         </el-table>
         <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
         <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
           v-model:limit="queryParams.pageSize" @pagination="getMessages" size="small"
           v-model:limit="queryParams.pageSize" @pagination="getMessages" size="small"
-          layout="total, prev, pager, next" />
+          layout="total, prev, next, jumper" />
       </div>
       </div>
     </el-dialog>
     </el-dialog>
+    <el-dialog title="发消息" v-model="addMessageDialog" width="450" center @close="closeMessageFormDialog">
+      <el-form ref="addMessageFormRef" v-model="messageData" label-width="100">
+        <el-row :gutter="10">
+          <el-col :span="24">
+            <el-form-item label="收件人">
+              <el-autocomplete :fetch-suggestions="querySearchAsync" :trigger-on-focus="true" style="width: 100%"
+                v-model="messageData.toNickName" placeholder="选择人员" popper-class="my-autocomplete"
+                @select="handleSelectEmployee">
+                <template #default="{ item }">
+                  <div style="
+                      display: flex;
+                      flex-direction: row;
+                      justify-content: space-between;
+                    ">
+                    <div class="name" style="font-size: 12px">
+                      {{ item.nickName }}
+                    </div>
+                    <span class="code" style="font-size: 10px; color: darkgrey">{{ item.userName }}</span>
+                  </div>
+                </template>
+              </el-autocomplete>
+            </el-form-item>
+          </el-col>
+          <el-col :span="24">
+            <el-form-item label="发送信息">
+              <el-input type="textarea" v-model="messageData.message"></el-input>
+            </el-form-item>
+          </el-col>
+        </el-row>
+      </el-form>
+      <template #footer>
+        <el-button @click="sendMessage">发送</el-button>
+      </template>
+    </el-dialog>
   </div>
   </div>
 </template>
 </template>
 
 
@@ -97,6 +133,7 @@ import Breadcrumb from '@/components/Breadcrumb'
 import TopNav from '@/components/TopNav'
 import TopNav from '@/components/TopNav'
 import Hamburger from '@/components/Hamburger'
 import Hamburger from '@/components/Hamburger'
 import Screenfull from '@/components/Screenfull'
 import Screenfull from '@/components/Screenfull'
+import { selectUserList, getInfo } from "@/api/business/noCurrentReject";
 // import SizeSelect from '@/components/SizeSelect'
 // import SizeSelect from '@/components/SizeSelect'
 // import HeaderSearch from '@/components/HeaderSearch'
 // import HeaderSearch from '@/components/HeaderSearch'
 // import RuoYiGit from '@/components/RuoYi/Git'
 // import RuoYiGit from '@/components/RuoYi/Git'
@@ -119,12 +156,19 @@ const messageCount = ref(0)
 const showMessageDialog = ref(false)
 const showMessageDialog = ref(false)
 const tenantLoading = ref(false)
 const tenantLoading = ref(false)
 const showDialog = ref(false)
 const showDialog = ref(false)
+const addMessageDialog = ref(false)
 const tenantList = ref([])
 const tenantList = ref([])
 const messageList = ref([])
 const messageList = ref([])
+const messageData = ref({
+  fromUserId: useUserStore().user.userId,
+  toUserId: null,
+  toUserName: null,
+  toNickName: null,
+  message: null
+})
 const currentTenantName = ref(getTenant().tenantName)
 const currentTenantName = ref(getTenant().tenantName)
 const total = ref(0)
 const total = ref(0)
 const queryParams = ref({
 const queryParams = ref({
-  toUserId: useUserStore().userId,
   pageSize: 10,
   pageSize: 10,
   pageNum: 1
   pageNum: 1
 })
 })
@@ -144,6 +188,10 @@ function handleCommand(command) {
     case 'message':
     case 'message':
       showMessageDialog.value = true
       showMessageDialog.value = true
       getMessages()
       getMessages()
+      break
+    case 'sendMessage':
+      addMessageDialog.value = true
+      break
     default:
     default:
       break
       break
   }
   }
@@ -210,7 +258,8 @@ const messageCountChanged = (count) => {
 
 
 }
 }
 const getMessages = () => {
 const getMessages = () => {
-  console.log(queryParams.value)
+  console.log(userStore)
+  queryParams.value.toUserId = useUserStore().user.userId
   listMessage(queryParams.value).then(res => {
   listMessage(queryParams.value).then(res => {
     if (res.code === 200) {
     if (res.code === 200) {
       messageList.value = res.rows
       messageList.value = res.rows
@@ -223,6 +272,35 @@ const getMessages = () => {
   })
   })
 }
 }
 
 
+const closeMessageFormDialog = () => {
+  addMessageDialog.value = false
+  messageData.value = {
+    fromUserId: useUserStore().user.userId,
+    toUserId: null,
+    toUserName: null,
+    toNickName: null,
+    message: null
+  }
+}
+function querySearchAsync(queryString, cb) {
+  if (queryString) {
+    selectUserList(queryString).then((res) => {
+      cb(res.rows);
+    });
+  }
+}
+
+function handleSelectEmployee(item) {
+  messageData.value.toNickName = item.nickName;
+  messageData.value.toUserId = item.userId;
+  messageData.value.toUserName = item.userName;
+}
+
+function sendMessage() {
+  useMessageStore().sendMsg(messageData.value)
+  closeMessageFormDialog()
+}
+
 onMounted(() => {
 onMounted(() => {
   window.addEventListener('messageChange', (target) => {
   window.addEventListener('messageChange', (target) => {
     const count = target.detail
     const count = target.detail

+ 6 - 2
src/permission.js

@@ -19,6 +19,8 @@ router.beforeEach((to, from, next) => {
   if (getToken()) {
   if (getToken()) {
     to.meta.title && useSettingsStore().setTitle(to.meta.title)
     to.meta.title && useSettingsStore().setTitle(to.meta.title)
     useSettingsStore().initGenLotBySub()
     useSettingsStore().initGenLotBySub()
+    useSettingsStore().initShowMessage()
+    useSettingsStore().initShowNotification()
     /* has token*/
     /* has token*/
     if (to.path === '/login') {
     if (to.path === '/login') {
       next({ path: '/' })
       next({ path: '/' })
@@ -39,8 +41,10 @@ router.beforeEach((to, from, next) => {
             next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
             next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
           })
           })
           // console.log(useUserStore().user.userId)
           // console.log(useUserStore().user.userId)
-          useMessageStore().connection(useUserStore().user.userId, getToken())
-          useMessageStore().initWebsocket()
+          if (useSettingsStore().showMessage) {
+            useMessageStore().connection(useUserStore().user.userId, getToken())
+            useMessageStore().initWebsocket()
+          }
         }).catch(err => {
         }).catch(err => {
           useUserStore().logOut().then(() => {
           useUserStore().logOut().then(() => {
             ElMessage.error(err)
             ElMessage.error(err)

+ 17 - 1
src/store/modules/settings.js

@@ -19,7 +19,9 @@ const useSettingsStore = defineStore(
       fixedHeader: storageSetting.fixedHeader === undefined ? fixedHeader : storageSetting.fixedHeader,
       fixedHeader: storageSetting.fixedHeader === undefined ? fixedHeader : storageSetting.fixedHeader,
       sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo,
       sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo,
       dynamicTitle: storageSetting.dynamicTitle === undefined ? dynamicTitle : storageSetting.dynamicTitle,
       dynamicTitle: storageSetting.dynamicTitle === undefined ? dynamicTitle : storageSetting.dynamicTitle,
-      genLotBySub: false
+      genLotBySub: false,
+      showMessage: false,
+      showNotification: false
     }),
     }),
     actions: {
     actions: {
       // 修改布局设置
       // 修改布局设置
@@ -39,6 +41,20 @@ const useSettingsStore = defineStore(
           // console.log(res)
           // console.log(res)
           this.genLotBySub = res.msg == 'true'
           this.genLotBySub = res.msg == 'true'
         })
         })
+      },
+      initShowMessage(config) {
+        getConfigKey('business.sys.message').then(res => {
+          // console.log(res)
+          this.showMessage = res.msg == 'true'
+          console.log('是否显示站内信', this.showMessage)
+        })
+      },
+      initShowNotification(config) {
+        getConfigKey('business.sys.showAffiche').then(res => {
+          // console.log(res)
+          this.showNotification = res.msg == 'true'
+          console.log('是否显示公告', this.showNotification)
+        })
       }
       }
     }
     }
   })
   })

+ 38 - 18
src/utils/request.js

@@ -6,11 +6,25 @@ import { tansParams, blobValidate } from '@/utils/ruoyi'
 import cache from '@/plugins/cache'
 import cache from '@/plugins/cache'
 import { saveAs } from 'file-saver'
 import { saveAs } from 'file-saver'
 import useUserStore from '@/store/modules/user'
 import useUserStore from '@/store/modules/user'
+import useSettingsStore from '@/store/modules/settings'
 import Notification from '../plugins/notification'
 import Notification from '../plugins/notification'
 // import emitter from '../eventBus'
 // import emitter from '../eventBus'
 // import { getCurrentInstance } from 'vue';
 // import { getCurrentInstance } from 'vue';
 // import { reject } from 'lodash-es'
 // import { reject } from 'lodash-es'
 
 
+const beforeNotification = ['\/ezhizao-dms-sys\/getInfo', '\/ezhizao-dms-sys\/getRouters', '\/ezhizao-dms-sys\/system\/config\/configKey\/']
+const checkBeforeUrl = (url) => {
+  let checked = false
+  // console.log(url)
+  beforeNotification.forEach(t => {
+    let reg = new RegExp('^' + t)
+    // console.log(t, reg.test(url))
+    checked = checked || reg.test(url)
+  })
+  // console.log(checked)
+  return checked
+}
+
 let downloadLoadingInstance
 let downloadLoadingInstance
 // 是否显示重新登录
 // 是否显示重新登录
 export let isRelogin = { show: false }
 export let isRelogin = { show: false }
@@ -51,24 +65,30 @@ service.interceptors.request.use(
     let notifications = []
     let notifications = []
     // 当登录状态为已登录时才可以获取公告
     // 当登录状态为已登录时才可以获取公告
     // console.log(config)
     // console.log(config)
-    if (getToken() && !isToken && tenantInfo && config.url != '/ezhizao-dms-sys/getInfo' && config.url != '/ezhizao-dms-sys/getRouters') {
+    // console.log(checkBeforeUrl(config.url))
+    if (getToken() && !isToken && tenantInfo && !checkBeforeUrl(config.url)) {
       // 所有条件都具备的情况下需先请求公告
       // 所有条件都具备的情况下需先请求公告
-      // let url = import.meta.env.VITE_APP_BASE_API + '/business/notification/getUnshowedNotification'
-      // const res = await axios({
-      //   url: url,
-      //   method: 'get',
-      //   headers: {
-      //     Authorization: 'Bearer ' + getToken(),
-      //     tenantId: getTenant().tenantId,
-      //     appKey: 'ezhizao-identity'
-      //   }
-      // })
-      // if (res.data.code == 200) {
-
-      // } else if (res.data.code == 202) {
-      //   notifications = res.data.data
-      //   requestable = false
-      // }
+      let url = import.meta.env.VITE_APP_BASE_API + '/business/notification/getUnshowedNotification'
+      const showNotification = useSettingsStore().showNotification
+      console.log('是否显示公告', showNotification)
+      if (showNotification) {
+        const res = await axios({
+          url: url,
+          method: 'get',
+          headers: {
+            Authorization: 'Bearer ' + getToken(),
+            tenantId: getTenant().tenantId,
+            appKey: 'ezhizao-identity'
+          }
+        })
+        if (res.data.code == 200) {
+        } else if (res.data.code == 202) {
+          notifications = res.data.data
+          requestable = false
+          // showDialog()
+        }
+      }
+      // 
     }
     }
     // get请求映射params参数
     // get请求映射params参数
     if (config.method === 'get' && config.params) {
     if (config.method === 'get' && config.params) {
@@ -168,7 +188,7 @@ service.interceptors.response.use(
       ElMessage({ message: message, type: 'error', duration: 5 * 1000 })
       ElMessage({ message: message, type: 'error', duration: 5 * 1000 })
     } else if (message.includes('SHOW NOTIFICATION')) {
     } else if (message.includes('SHOW NOTIFICATION')) {
       // showDialog(data)
       // showDialog(data)
-      // Notification(data[0])
+      Notification(data[0])
     } else {
     } else {
       ElMessage({ message: message, type: 'error', duration: 5 * 1000 })
       ElMessage({ message: message, type: 'error', duration: 5 * 1000 })
     }
     }

+ 15 - 12
src/views/index.vue

@@ -13,8 +13,8 @@
           </div>
           </div>
           <div class="number-label">{{ totalCompanies }} 人</div>
           <div class="number-label">{{ totalCompanies }} 人</div>
         </div> -->
         </div> -->
-        <!-- <div class="notifications-header">公告</div>
-        <el-row :gutter="5">
+        <div v-if="showNotification" class="notifications-header">公告</div>
+        <el-row v-if="showNotification" :gutter="5">
           <el-col :span="8" v-for="item in notifications">
           <el-col :span="8" v-for="item in notifications">
             <el-card style="width: 100%;margin-bottom: 5px;" shadow="always" @click="showNotifiaction(item)">
             <el-card style="width: 100%;margin-bottom: 5px;" shadow="always" @click="showNotifiaction(item)">
               <template #header>
               <template #header>
@@ -23,16 +23,16 @@
                   </div>
                   </div>
                 </div>
                 </div>
               </template>
               </template>
-<div style="height: 40px;overflow: clip;">
-  <div v-html="item.content" style="height: 100%;">
-  </div>
-</div>
-<div class="footer">
-  {{ item.createTime }}
-</div>
-</el-card>
-</el-col>
-</el-row> -->
+              <div style="height: 40px;overflow: clip;">
+                <div v-html="item.content" style="height: 100%;">
+                </div>
+              </div>
+              <div class="footer">
+                {{ item.createTime }}
+              </div>
+            </el-card>
+          </el-col>
+        </el-row>
 
 
         <!-- <el-row v-for="item in notifications" style="padding: 5px 10px;">
         <!-- <el-row v-for="item in notifications" style="padding: 5px 10px;">
           {{ item.title }}
           {{ item.title }}
@@ -71,6 +71,7 @@
 import { parseTime } from '@/utils/tools.js'
 import { parseTime } from '@/utils/tools.js'
 import { listNotification } from '@/api/business/notification'
 import { listNotification } from '@/api/business/notification'
 import notification from '@/views/dialog/notification'
 import notification from '@/views/dialog/notification'
+import useSettingsStore from '@/store/modules/settings'
 
 
 // import { index } from '@/api/business/production'
 // import { index } from '@/api/business/production'
 
 
@@ -151,12 +152,14 @@ let currentMonth = ref('')
 let statisticDom, statistic
 let statisticDom, statistic
 const notifications = ref([])
 const notifications = ref([])
 const notificationRef = ref(null)
 const notificationRef = ref(null)
+const showNotification = ref(false)
 
 
 onMounted(() => {
 onMounted(() => {
   currentMonth.value = parseTime(new Date(), '{y}-{m}')
   currentMonth.value = parseTime(new Date(), '{y}-{m}')
   //statisticDom = document.getElementById('information-statistic')
   //statisticDom = document.getElementById('information-statistic')
   //statistic = echarts.init(statisticDom)
   //statistic = echarts.init(statisticDom)
   //getCurrentMonthDayArr()
   //getCurrentMonthDayArr()
+  showNotifiaction.value = useSettingsStore().showNotification
   getList()
   getList()
 })
 })