push-config-edit.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. import {defineComponent, onMounted, reactive, ref} from "vue";
  2. import {NButton, NForm, NFormItemGi, NGrid, NInput, NInputNumber, NSelect, NSpace, useMessage} from "naive-ui";
  3. import {getSelectDataFromObj} from "@/utils/objectUtil";
  4. import {clientType, deviceType} from "@/utils/constant";
  5. import {appSendConfigSave, appSendConfigUpdate} from "@views/message/api";
  6. export default defineComponent({
  7. name: 'push-config-edit',
  8. props: {
  9. editMode: {
  10. type: String,
  11. required: true
  12. },
  13. rowData: {
  14. type: Object,
  15. required: false
  16. },
  17. appData: {
  18. type: [] as any,
  19. required: true
  20. },
  21. },
  22. emits: ['close', 'getList'],
  23. setup(props, {slots, attrs, emit}) {
  24. const message = useMessage()
  25. const btnLoading = ref(false)
  26. const forms = reactive({
  27. name: null, // 平台名称
  28. sender: null, // 平台标识
  29. appKey: null, // 应用端
  30. accessUrl: null, // 接入地址
  31. clientId: null, // 客户端
  32. apnsProduction: null as any, // 推送环境
  33. account: null, // 接入账号
  34. password: null, // 接入密码
  35. timeToLive: null as any, // 离线保存时长
  36. extendData: null, // 扩展参数
  37. deviceType: null, // 设备类型
  38. })
  39. const formsRef = ref()
  40. const state = reactive({
  41. rowData: null as any,
  42. musicSheetCategories: [] as any,
  43. appData: [] as any,
  44. })
  45. onMounted(async () => {
  46. state.rowData = props.rowData
  47. if (props.editMode == 'edit' && props.rowData) {
  48. forms.name = state.rowData.name
  49. forms.sender = state.rowData.sender
  50. forms.appKey = state.rowData.appKey
  51. forms.clientId = state.rowData.clientId
  52. forms.apnsProduction = state.rowData.apnsProduction
  53. forms.account = state.rowData.account
  54. forms.password = state.rowData.password
  55. forms.timeToLive = Number.parseFloat(state.rowData.timeToLive)/3600
  56. forms.accessUrl = state.rowData.accessUrl
  57. forms.extendData = state.rowData.extendData
  58. forms.deviceType = state.rowData.deviceType
  59. }
  60. // 客户端
  61. // state.appData = []
  62. // const {data} = await sysApplicationPage({page: 1, rows: 999})
  63. // if (data && data.rows) {
  64. // data.rows.forEach((item: any) => {
  65. // state.appData.push({label: item.appName, value: item.id + ''})
  66. // })
  67. // }
  68. })
  69. const onSubmit = async () => {
  70. formsRef.value.validate(async (error: any) => {
  71. if (error) return false
  72. btnLoading.value = true
  73. try {
  74. let res;
  75. if (props.editMode == 'add') {
  76. res = await appSendConfigSave(
  77. {
  78. ...forms,
  79. timeToLive: Number.parseFloat(forms.timeToLive) * 3600
  80. }
  81. ) as any;
  82. } else {
  83. res = await appSendConfigUpdate(
  84. {
  85. ...forms,
  86. id: state.rowData.id,
  87. timeToLive: Number.parseFloat(forms.timeToLive) * 3600
  88. }
  89. ) as any;
  90. }
  91. if (res && res.code === 200) {
  92. emit('close')
  93. emit('getList')
  94. }
  95. } catch (error) {
  96. }
  97. btnLoading.value = false
  98. })
  99. }
  100. return () => {
  101. return (
  102. <div style="background: #fff; padding-top: 12px">
  103. <NForm
  104. ref={formsRef}
  105. labelPlacement="top"
  106. model={forms}
  107. label-placement="left"
  108. label-width="100"
  109. >
  110. <NGrid cols={2}>
  111. <NFormItemGi
  112. label="平台名称"
  113. path="name"
  114. rule={[
  115. {
  116. required: true,
  117. message: '请输入平台名称'
  118. }
  119. ]}
  120. >
  121. <NInput
  122. v-model:value={forms.name}
  123. placeholder="请输入平台名称"
  124. clearable
  125. />
  126. </NFormItemGi>
  127. <NFormItemGi
  128. label="平台标识"
  129. path="sender"
  130. rule={[
  131. {
  132. required: true,
  133. message: '请输入平台标识'
  134. }
  135. ]}
  136. >
  137. <NInput
  138. v-model:value={forms.sender}
  139. placeholder="请输入平台标识"
  140. clearable
  141. />
  142. </NFormItemGi>
  143. <NFormItemGi
  144. label="接入应用"
  145. path="appKey"
  146. rule={[
  147. {
  148. required: true,
  149. message: '请输入接入应用'
  150. }
  151. ]}
  152. >
  153. <NSelect
  154. v-model:value={forms.appKey}
  155. placeholder="请输入接入应用"
  156. options={props.appData}
  157. clearable
  158. />
  159. </NFormItemGi>
  160. <NFormItemGi
  161. label="客户端"
  162. path="clientId"
  163. rule={[
  164. {
  165. required: true,
  166. message: '请选择客户端'
  167. }
  168. ]}
  169. >
  170. <NSelect
  171. v-model:value={forms.clientId}
  172. options={getSelectDataFromObj(clientType)}
  173. placeholder="请选择客户端"
  174. clearable
  175. />
  176. </NFormItemGi>
  177. <NFormItemGi
  178. label="接入地址"
  179. path="accessUrl"
  180. rule={[
  181. {
  182. required: true,
  183. message: '请输入接入地址'
  184. }
  185. ]}
  186. >
  187. <NInput
  188. v-model:value={forms.accessUrl}
  189. placeholder="请输入接入地址"
  190. clearable
  191. />
  192. </NFormItemGi>
  193. <NFormItemGi
  194. label="推送环境"
  195. path="apnsProduction"
  196. rule={[
  197. {
  198. required: true,
  199. message: '请输入推送环境',
  200. type: 'boolean'
  201. }
  202. ]}
  203. >
  204. <NSelect
  205. v-model:value={forms.apnsProduction}
  206. placeholder="请输入推送环境"
  207. options={[
  208. {
  209. label: '线上',
  210. value: true
  211. }, {
  212. label: '开发',
  213. value: false
  214. }
  215. ] as any}
  216. clearable
  217. />
  218. </NFormItemGi>
  219. <NFormItemGi
  220. label="接入key"
  221. path="account"
  222. rule={[
  223. {
  224. required: true,
  225. message: '请输入接入key'
  226. }
  227. ]}
  228. >
  229. <NInput
  230. v-model:value={forms.account}
  231. placeholder="请输入接入key"
  232. clearable
  233. />
  234. </NFormItemGi>
  235. <NFormItemGi
  236. label="接入密钥"
  237. path="password"
  238. rule={[
  239. {
  240. required: true,
  241. message: '请输入接入密钥'
  242. }
  243. ]}
  244. >
  245. <NInput
  246. v-model:value={forms.password}
  247. placeholder="请输入接入密码"
  248. clearable
  249. />
  250. </NFormItemGi>
  251. <NFormItemGi
  252. label="离线保留时长(小时)"
  253. path="timeToLive"
  254. rule={[
  255. {
  256. required: true,
  257. message: '请输入离线保留时长(小时)'
  258. }
  259. ]}
  260. >
  261. <NInputNumber
  262. v-model:value={forms.timeToLive}
  263. placeholder="请输入离线保留时长(小时)"
  264. min={0}
  265. />
  266. </NFormItemGi>
  267. <NFormItemGi
  268. label="设备类型"
  269. path="deviceType"
  270. rule={[
  271. {
  272. required: false,
  273. message: '请选择设备类型'
  274. }
  275. ]}
  276. >
  277. <NSelect
  278. placeholder="请选择设备类型"
  279. v-model:value={forms.deviceType}
  280. options={getSelectDataFromObj(deviceType)}
  281. clearable
  282. />
  283. </NFormItemGi>
  284. </NGrid>
  285. <NGrid cols={1}>
  286. <NFormItemGi
  287. label="拓展参数"
  288. path="extendData"
  289. rule={[
  290. {
  291. required: false,
  292. message: '请输入拓展参数'
  293. }
  294. ]}
  295. >
  296. <NInput
  297. v-model:value={forms.extendData}
  298. placeholder="请输入拓展参数"
  299. autosize={{minRows: 3}}
  300. type={'textarea'}
  301. />
  302. </NFormItemGi>
  303. </NGrid>
  304. </NForm>
  305. <NSpace justify="end">
  306. <NButton onClick={() => emit('close')}>取消</NButton>
  307. <NButton type="primary" onClick={onSubmit}
  308. loading={btnLoading.value}
  309. disabled={btnLoading.value}
  310. >
  311. 保存
  312. </NButton>
  313. </NSpace>
  314. </div>
  315. )
  316. }
  317. }
  318. })