選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

editDialog.vue 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <el-dialog v-model="isShow" width="50%" :title="title">
  3. <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="130px" class="demo-ruleForm" status-icon
  4. size="large" v-loading="isLoading">
  5. <div class="user-select-content">
  6. <el-form-item label="消息客户端" prop="clientId" style="width: 50%">
  7. <selectClientMessage v-model="ruleForm.clientId" messageType="APP" />
  8. </el-form-item>
  9. <el-form-item label="推送时间" prop="sendTime" style="width: 50%">
  10. <el-date-picker unlink-panels v-model="ruleForm.sendTime" type="datetime" placeholder="请选择推送时间,不选择则立即发送"
  11. :default-time="new Date()" style="width: 100%" value-format="YYYY-MM-DDTHH:mm:ss" :disabled-date="(time) => {
  12. return time.getTime() + 86400000 < Date.now() //禁止选择今天以前的时间
  13. }
  14. " />
  15. </el-form-item>
  16. </div>
  17. <div class="user-select-content">
  18. <el-form-item label="用户选择" style="width: 50%" prop="userInfo">
  19. <selectUserId v-model="extras.userInfo" :width="clientMessWidth" :userList="userList"
  20. @handleUserId="handleUserId" type="JPUSH" />
  21. </el-form-item>
  22. <el-form-item label="用户组选择" style="width: 50%" prop="staffIdentityTypes">
  23. <selectGroup v-model="ruleForm.userGroupInfo" :width="clientMessWidth" @handleUserGroupId="handleUserGroupId"
  24. type="JPUSH" />
  25. </el-form-item>
  26. </div>
  27. <el-form-item label="消息标题" prop="title" v-if="isStatus == 'all'">
  28. <el-input maxlength="60" v-trim clearable v-model="ruleForm.title" placeholder="请输入消息标题" />
  29. </el-form-item>
  30. <el-form-item label="通知栏标题" prop="title" v-if="isStatus == 'notifications'">
  31. <el-input maxlength="60" v-trim clearable v-model="ruleForm.title" placeholder="请输入通知栏标题" />
  32. </el-form-item>
  33. <el-form-item label="通知栏标题" prop="notificationTitle" v-if="isStatus == 'all'">
  34. <el-input maxlength="60" v-trim clearable v-model="ruleForm.notificationTitle" placeholder="请输入通知栏标题" />
  35. </el-form-item>
  36. <template v-if="isStatus == 'all' || isStatus == 'notifications'">
  37. <el-form-item label="通知栏内容" prop="notificationContent">
  38. <el-input maxlength="60" v-trim clearable placeholder="请输入通知栏内容" v-model="ruleForm.notificationContent" />
  39. </el-form-item>
  40. <el-form-item label="通知栏额外信息" prop="notificationExtras">
  41. <el-input maxlength="60" v-trim clearable placeholder="请输入通知栏额外信息" v-model="ruleForm.notificationExtras" />
  42. </el-form-item>
  43. </template>
  44. <el-form-item label="自定义消息标题" prop="msgTitle" v-if="isStatus == 'all'">
  45. <el-input maxlength="60" v-trim clearable placeholder="请输入自定义消息标题" v-model="ruleForm.msgTitle" />
  46. </el-form-item>
  47. <el-form-item label="自定义消息标题" prop="title" v-if="isStatus == 'custom'">
  48. <el-input maxlength="60" v-trim clearable placeholder="请输入自定义消息标题" v-model="ruleForm.title" />
  49. </el-form-item>
  50. <template v-if="isStatus == 'all' || isStatus == 'custom'">
  51. <el-form-item label="自定义消息内容" prop="msgContent">
  52. <el-input maxlength="200" v-trim clearable placeholder="请输入自定义消息内容" v-model="ruleForm.msgContent"
  53. type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" />
  54. </el-form-item>
  55. <el-form-item label="自定义额外信息" prop="msgExtra">
  56. <el-input maxlength="200" v-trim clearable placeholder="请输入自定义消息额外信息" v-model="ruleForm.msgExtra"
  57. type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" />
  58. </el-form-item>
  59. </template>
  60. <el-form-item>
  61. <div style="width: 100%" ref="inputRef">
  62. <el-button type="primary" @click="submitForm(ruleFormRef)">
  63. 推送消息
  64. </el-button>
  65. <el-button @click="resetForm(ruleFormRef)">重置</el-button>
  66. </div>
  67. </el-form-item>
  68. </el-form>
  69. </el-dialog>
  70. </template>
  71. <!-- web端信息推送 -->
  72. <script lang="ts" setup>
  73. import { ElMessage } from 'element-plus'
  74. // 请求函数
  75. // @ts-ignore
  76. import BaseService from '@/utils/baseService'
  77. import { computed, nextTick, onMounted, reactive, ref } from 'vue'
  78. import type { FormInstance, FormRules } from 'element-plus'
  79. import selectClientMessage from '@/views/messagePush/pushManagement/components/selectClientMessage/index.vue'
  80. import selectUserId from '@/views/messagePush/pushManagement/components/selectUserId/index.vue'
  81. import selectGroup from '@/views/messagePush/pushManagement/components/selectGroup/index.vue'
  82. interface PropsType {
  83. modelValue: any
  84. dataList: any
  85. }
  86. const props = defineProps<PropsType>()
  87. const isStatus = ref('all')
  88. const title = computed(() => {
  89. let text: any = ''
  90. let description = props.dataList.description
  91. if (description) {
  92. description = description.split('-')
  93. text = description[description.length - 1]
  94. }
  95. return text
  96. })
  97. const emit = defineEmits(['update:modelValue', 'handleSendSuccess'])
  98. const isShow = computed({
  99. get: function () {
  100. if (props.modelValue) {
  101. getList() //获取详情数据回填
  102. nextTick(() => {
  103. clientMessWidth.value = inputRef.value.clientWidth
  104. })
  105. }
  106. return props.modelValue
  107. },
  108. set: function (newValue) {
  109. emit('update:modelValue', newValue)
  110. },
  111. })
  112. const getList = () => {
  113. // 重置
  114. ruleForm.value = {
  115. notificationTitle: '',
  116. notificationContent: '',
  117. title: '', //消息标题
  118. clientId: '',
  119. sendTime: '', //发送时间
  120. // registrationIdList: ['170976fa8b9699c5b8b'],
  121. registrationIdList: [],
  122. notificationExtras: '',
  123. msgTitle: '',
  124. msgContent: '',
  125. msgExtra: '',
  126. userGroupInfo: [], //用户组信息
  127. }
  128. isLoading.value = true
  129. BaseService.post('/msgw/message/view', {
  130. id: props.dataList.id,
  131. }).then((res: any) => {
  132. if (res && res.statusCode === 0) {
  133. let bizContent = res.data
  134. let data = bizContent.data || []
  135. for (const key in ruleForm.value) {
  136. ruleForm.value[key] = data[key]
  137. }
  138. console.log(data)
  139. const keys = Object.keys(data)
  140. console.log(keys)
  141. if (!keys.includes('notificationContent')) {
  142. isStatus.value = 'custom'
  143. }
  144. if (!keys.includes('msgContent')) {
  145. isStatus.value = 'notifications'
  146. }
  147. getUserInfo(
  148. data.openIdList,
  149. data.registrationIdList,
  150. data.wxOpenidList,
  151. data.mobileList,
  152. data.mpOpenidList
  153. )
  154. } else {
  155. ElMessage.error(res.message)
  156. }
  157. })
  158. }
  159. const userList = ref<any>([])
  160. // 获取用户信息
  161. const getUserInfo = async (
  162. openIdList,
  163. ridList,
  164. wxOpenidList,
  165. mobileList,
  166. mpOpenidList
  167. ) => {
  168. if (
  169. !openIdList &&
  170. !ridList &&
  171. !wxOpenidList &&
  172. !mobileList &&
  173. !mpOpenidList
  174. ) {
  175. return
  176. }
  177. await BaseService.post('/msgw/push/getbyconditionlist', {
  178. openIdList,
  179. ridList,
  180. wxOpenidList,
  181. mobileList,
  182. mpOpenidList,
  183. })
  184. .then((res: any) => {
  185. if (res && res.statusCode === 0) {
  186. let bizContent = res.data
  187. let data = bizContent.data || []
  188. userList.value = data
  189. console.log(data)
  190. } else {
  191. ElMessage.error(res.message)
  192. }
  193. })
  194. .finally(() => {
  195. isLoading.value = false
  196. })
  197. }
  198. interface RuleForm {
  199. notificationTitle: string
  200. notificationContent: string
  201. clientId: string
  202. registrationIdList: any
  203. sendTime: string
  204. notificationExtras: string
  205. msgTitle: string
  206. title: string
  207. msgContent: string
  208. msgExtra: string
  209. userGroupInfo: any
  210. }
  211. const ruleFormRef = ref<FormInstance>()
  212. const isLoading = ref(false) //加载效果
  213. let inputRef = ref()
  214. const clientMessWidth = ref(400)
  215. const extras: any = reactive({
  216. userInfo: [], //用户信息
  217. staffIdentityTypes: [], //用户组
  218. })
  219. const ruleForm = ref<RuleForm>({
  220. notificationTitle: '',
  221. notificationContent: '',
  222. title: '', //消息标题
  223. clientId: '',
  224. sendTime: '', //发送时间
  225. // registrationIdList: ['170976fa8b9699c5b8b'],
  226. registrationIdList: [],
  227. notificationExtras: '',
  228. msgTitle: '',
  229. msgContent: '',
  230. msgExtra: '',
  231. userGroupInfo: [], //用户组信息
  232. })
  233. const checkOpenIdList = (rule: any, value: any, callback: any) => {
  234. if (
  235. !ruleForm.value.registrationIdList.length &&
  236. !userGroupList.value.length
  237. ) {
  238. // callback(new Error('请至少选择一个用户或用户组'))
  239. callback()
  240. } else {
  241. callback()
  242. }
  243. }
  244. const rules = reactive<any>({
  245. title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  246. notificationTitle: [
  247. { required: true, message: '请输入消息标题', trigger: 'blur' },
  248. ],
  249. notificationContent: [
  250. { required: true, message: '请输入消息内容', trigger: 'blur' },
  251. ],
  252. clientId: [{ required: true, message: '请选择消息标题', trigger: 'blur' }],
  253. msgTitle: [
  254. { required: true, message: '请输入自定义消息标题', trigger: 'blur' },
  255. ],
  256. msgContent: [
  257. { required: true, message: '请输入自定义消息内容', trigger: 'blur' },
  258. ],
  259. userInfo: [{ validator: checkOpenIdList, trigger: 'blur' }],
  260. staffIdentityTypes: [{ validator: checkOpenIdList, trigger: 'blur' }],
  261. })
  262. const resetForm = (formEl: FormInstance | undefined) => {
  263. if (!formEl) return
  264. formEl.resetFields()
  265. }
  266. // 用户组所有的id
  267. const userGroupList = ref<any>([])
  268. // 当前选择的用户端数据
  269. const handleUserId = (row) => {
  270. console.log(row)
  271. ruleForm.value.registrationIdList = row.map((item) => item.registrationId)
  272. }
  273. const handleUserGroupId = (row) => {
  274. userGroupList.value = row
  275. }
  276. const submitCode = {
  277. allUser: {
  278. //发送给所有用户
  279. all: '/msgw/channel/jpushallappnmedit',
  280. notifications: '/msgw/channel/jpushallappnedit', //通知栏
  281. custom: '/msgw/channel/jpushallappmedit',
  282. },
  283. appointUser: {
  284. //发送给指定用户
  285. all: '/msgw/channel/jpushallridnmedit',
  286. notifications: '/msgw/channel/jpushallridnedit',
  287. custom: '/msgw/channel/jpushallridmedit',
  288. },
  289. }
  290. // 请求参数处理
  291. const handleParams = () => {
  292. let params: any = {}
  293. // 参数处理
  294. for (const key in ruleForm.value) {
  295. // 需要跳过的
  296. if (['userGroupInfo'].includes(key)) continue
  297. const element = ruleForm.value[key]
  298. if (element || element === 0) {
  299. if (Array.isArray(element) && element.length === 0) {
  300. continue
  301. } else {
  302. params[key] = element
  303. }
  304. }
  305. }
  306. params.id = props.dataList.id
  307. return params
  308. }
  309. const submitForm = async (formEl: FormInstance | undefined) => {
  310. if (!formEl) return
  311. await formEl.validate((valid, fields) => {
  312. if (valid) {
  313. let params: any = handleParams()
  314. let ifcodeObj: any = {}
  315. if (params.registrationIdList) {
  316. ifcodeObj = submitCode.appointUser
  317. } else {
  318. ifcodeObj = submitCode.allUser
  319. }
  320. submitHandle(ifcodeObj[isStatus.value], params, formEl)
  321. }
  322. })
  323. }
  324. // 消息推送
  325. const submitHandle = async (ifcode, params: any, formEl: FormInstance) => {
  326. isLoading.value = true
  327. console.log(ifcode, params)
  328. BaseService.post(ifcode, params)
  329. .then((res: any) => {
  330. isShow.value = false
  331. emit('handleSendSuccess')
  332. if (res && res.statusCode === 0) {
  333. ElMessage.success('消息修改成功')
  334. } else {
  335. ElMessage.error(`消息修改失败,原因:${res.message}`)
  336. }
  337. })
  338. .finally(() => {
  339. isLoading.value = false
  340. })
  341. }
  342. </script>
  343. <style scoped lang="less">
  344. .user-select-content {
  345. display: flex;
  346. }
  347. </style>