push-config-edit.tsx 9.7 KB

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