add.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <div class="addIdx">
  3. <s-header :name="titleName" :noback="false"></s-header>
  4. <van-form show-error-message @submit="onSubmit">
  5. <div class="cust_vantBorder">
  6. <div class="kBordBott">
  7. <van-field type="number" colon :border="false" required v-model="cofficentForm.version" clearable
  8. name="version" :label="$t('apkManage.add.version')" :placeholder="$t('apkManage.add.versionPlace')" :rules="[
  9. {
  10. required: true,
  11. message: $t('apkManage.add.versionPlace'),
  12. },
  13. ]" />
  14. </div>
  15. <div class="kBordBott">
  16. <van-field colon :border="false" required v-model="cofficentForm.versionName" clearable name="versionName"
  17. :label="$t('apkManage.add.versionName')" :placeholder="$t('apkManage.add.versionNamePlace')" :rules="[
  18. {
  19. required: true,
  20. message: $t('apkManage.add.versionNamePlace'),
  21. },
  22. ]" />
  23. </div>
  24. <div class="kBordBott">
  25. <van-field colon :border="false" required @click-input="busiInpClk" readonly clearable
  26. v-model="cofficentForm.modelName" name="modelName" :label="$t('apkManage.add.model')"
  27. :placeholder="$t('apkManage.add.modelPlace')" :rules="[
  28. {
  29. required: true,
  30. message: $t('apkManage.add.modelPlace'),
  31. trigger: ['onChange', 'onSubmit'],
  32. },
  33. ]">
  34. <template #right-icon>
  35. <div class="l-flex-RC">
  36. <van-icon v-if="cofficentForm.modelName" @click="
  37. cofficentForm.modelName = '';
  38. cofficentForm.model = '';
  39. " class="o-mr-6" name="clear" />
  40. <van-icon @click="busiInpClk" name="arrow-down" />
  41. </div>
  42. </template>
  43. </van-field>
  44. </div>
  45. </div>
  46. <div class="kBordBott">
  47. <van-field colon :border="false" required clearable name="isForce" :label="$t('apkManage.add.forceUpdate')"
  48. :placeholder="$t('apkManage.add.forceUpdatePlace')" :rules="[
  49. {
  50. required: true,
  51. message: $t('apkManage.add.forceUpdatePlace'),
  52. trigger: ['onChange', 'onSubmit'],
  53. },
  54. ]">
  55. <template #input>
  56. <van-radio-group v-model="cofficentForm.isForce" direction="horizontal">
  57. <van-radio name="true">{{ $t('apkManage.add.yes') }}</van-radio>
  58. <van-radio name="false">{{ $t('apkManage.add.no') }}</van-radio>
  59. </van-radio-group>
  60. </template>
  61. </van-field>
  62. </div>
  63. <div class="cust_vantBorder">
  64. <div class="kBordBott">
  65. <van-field type="number" colon :border="false" required v-model="cofficentForm.apkSize" clearable
  66. name="apkSize" :label="$t('apkManage.add.apkSize')" :placeholder="$t('apkManage.add.apkSizePlace')" :rules="[
  67. {
  68. required: true,
  69. message: $t('apkManage.add.apkSizePlace'),
  70. },
  71. ]" />
  72. </div>
  73. <div class="kBordBott">
  74. <van-field colon :border="false" required v-model="cofficentForm.downloadUrl" clearable name="downloadUrl"
  75. :label="$t('apkManage.add.downloadLink')" :placeholder="$t('apkManage.add.downloadLinkPlace')" :rules="[
  76. {
  77. required: true,
  78. message: $t('apkManage.add.downloadLinkPlace'),
  79. },
  80. ]" />
  81. </div>
  82. <div class="kBordBott">
  83. <van-field colon :border="false" required v-model="cofficentForm.versionInfo" clearable name="versionInfo"
  84. :label="$t('apkManage.add.versionIntroduction')" :placeholder="$t('apkManage.add.versionIntroductionPlace')"
  85. :rules="[
  86. {
  87. required: true,
  88. message: $t('apkManage.add.versionIntroductionPlace'),
  89. },
  90. ]" />
  91. </div>
  92. </div>
  93. <div style="margin: 16px">
  94. <van-button round block type="primary" native-type="submit">
  95. {{ titleName }}
  96. </van-button>
  97. </div>
  98. </van-form>
  99. <!-- 型号选择框 -->
  100. <van-popup v-model:show="busiPopShow" position="bottom">
  101. <van-picker :default-index="busiDefaIdx" :title="$t('apkManage.add.version')" :columns="busiPopList"
  102. :columns-field-names="busiPopFieldName" @confirm="busiPopConfirm" @cancel="busiPopShow = false" />
  103. </van-popup>
  104. </div>
  105. </template>
  106. <script>
  107. // 导入接口
  108. // 导入接口
  109. import { Api_postAddApk, Api_postUpdateApk } from "@/service/apkManage";
  110. import sHeader from "@/components/SimpleHeader";
  111. import { reactive, onMounted, ref } from "vue";
  112. import { Toast } from "vant";
  113. import { useRoute, useRouter } from "vue-router";
  114. import { useI18n } from "vue-i18n";
  115. import {styleUrl} from "../../common/js/utils";
  116. export default {
  117. components: { sHeader },
  118. setup() {
  119. const { t } = useI18n();
  120. const titleName = ref(t("apkManage.add.addTitle"));
  121. const route = useRoute();
  122. onMounted(() => {
  123. // 加载样式
  124. styleUrl('apkManage');
  125. const row = route.query.row ? JSON.parse(route.query.row) : {};
  126. // 看路径有没有id,有就是编辑
  127. if (row.id) {
  128. titleName.value = t("apkManage.add.editTitle");
  129. cofficentForm.value = row;
  130. // 转换成字符串
  131. cofficentForm.value.isForce = cofficentForm.value.isForce + '';
  132. cofficentForm.value.modelName = row.model;
  133. }
  134. });
  135. // 表单参数
  136. let cofficentForm = ref({
  137. apkSize: "",
  138. downloadUrl: "",
  139. isForce: "",
  140. version: "",
  141. versionInfo: "",
  142. versionName: "",
  143. model: "",
  144. modelName: "",
  145. });
  146. // 路由
  147. const router = useRouter();
  148. // 点击提交
  149. const onSubmit = async () => {
  150. // 如果是编辑
  151. let res;
  152. if (cofficentForm.value.id) {
  153. res = await Api_postUpdateApk(cofficentForm.value);
  154. } else {
  155. res = await Api_postAddApk(cofficentForm.value);
  156. }
  157. const { data } = res;
  158. if (data.code === "00000") {
  159. Toast(data.message);
  160. setTimeout(() => {
  161. router.back();
  162. }, 500);
  163. }
  164. };
  165. // 型号选择框框
  166. const busiPopShow = ref(false);
  167. const busiPopList = reactive([
  168. {
  169. name: "301ch",
  170. id: "301ch",
  171. },
  172. {
  173. name: "301en",
  174. id: "301en",
  175. },
  176. {
  177. name: "301enOffline",
  178. id: "301enOffline",
  179. },
  180. {
  181. name: "320ch",
  182. id: "320ch",
  183. },
  184. {
  185. name: "320en",
  186. id: "320en",
  187. },
  188. {
  189. name: "320enOffline",
  190. id: "320enOffline",
  191. },
  192. {
  193. name: "280ch",
  194. id: "280ch",
  195. },
  196. {
  197. name: "280en",
  198. id: "280en",
  199. },
  200. {
  201. name: "POP320ch",
  202. id: "POP320ch",
  203. },
  204. {
  205. name: "POP320en",
  206. id: "POP320en",
  207. }
  208. ]);
  209. const busiPopFieldName = reactive({
  210. text: "name",
  211. value: "id",
  212. });
  213. // 点击型号
  214. const busiInpClk = () => {
  215. busiPopShow.value = true;
  216. };
  217. const busiPopConfirm = (e) => {
  218. cofficentForm.value.model = e.id;
  219. cofficentForm.value.modelName = e.name;
  220. busiPopShow.value = false;
  221. };
  222. return {
  223. onSubmit,
  224. cofficentForm,
  225. titleName,
  226. busiPopShow,
  227. busiPopList,
  228. busiPopFieldName,
  229. busiInpClk,
  230. busiPopConfirm,
  231. };
  232. },
  233. };
  234. </script>
  235. <style lang="less" scoped>
  236. </style>