uploaddata.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view style="margin-top: 160rpx;"></view>
  6. <view @click="toRecord()">
  7. <view style="display: flex;justify-content: center;">
  8. <image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
  9. </view>
  10. <view style="display: flex;justify-content: center;">
  11. <p style="font-size: 30rpx;">查看修改/反馈记录</p>
  12. </view>
  13. </view>
  14. <view style="margin: 40rpx;">
  15. <uni-forms :modelValue="formData" validate-trigger="bind" err-show-type="undertext"
  16. label-width="150">
  17. <uni-forms-item name="play_number" label="小眼睛阅读数/播放量">
  18. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.play_number"
  19. placeholder="输入">
  20. </uni-easyinput>
  21. </uni-forms-item>
  22. <uni-forms-item name="like_number" label="点赞数">
  23. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.like_number"
  24. placeholder="输入">
  25. </uni-easyinput>
  26. </uni-forms-item>
  27. <uni-forms-item name="collect_number" label="收藏数">
  28. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.collect_number"
  29. placeholder="输入">
  30. </uni-easyinput>
  31. </uni-forms-item>
  32. <uni-forms-item name="comment_number" label="评论数">
  33. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.comment_number"
  34. placeholder="输入">
  35. </uni-easyinput>
  36. </uni-forms-item>
  37. </uni-forms>
  38. </view>
  39. <view style="margin: 0 40rpx;">
  40. <p style="margin-bottom: 20rpx;">上传小眼睛阅读数/播放量截图</p>
  41. <htz-image-upload :max="1" mediaType="image" name="file" :chooseNum="1" v-model="imageData"
  42. @chooseSuccess="ceshiChooseSuccess1">
  43. </htz-image-upload>
  44. </view>
  45. <view class="signup">
  46. <button type="default" class="but1" :loading="loading" @click="submit()">
  47. 提交数据</button>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import mvBar from "@/components/mys_navBar/mysNavBar";
  53. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  54. import getPolicyEncode from '@/components/obs/getPolicy.js';
  55. import getSignature from '@/components/obs/GetSignature.js';
  56. export default {
  57. components: {
  58. mvBar,
  59. htzImageUpload,
  60. },
  61. data() {
  62. return {
  63. taskId: "",
  64. dataStatus: "",
  65. imageData: [],
  66. formData: {
  67. play_number: "",
  68. like_number: "",
  69. collect_number: "",
  70. commet_number: "",
  71. },
  72. // rules: {
  73. // // 对play_number字段进行必填验证
  74. // play_number: {
  75. // rules: [{
  76. // required: true,
  77. // errorMessage: '10位以内的数字',
  78. // },
  79. // {
  80. // minLength: 1,
  81. // maxLength: 10,
  82. // errorMessage: '10位以内的数字',
  83. // }
  84. // ]
  85. // },
  86. // // 对like_number字段进行必填验证
  87. // like_number: {
  88. // rules: [{
  89. // required: true,
  90. // errorMessage: '10位以内的数字',
  91. // },
  92. // {
  93. // minLength: 1,
  94. // maxLength: 10,
  95. // errorMessage: '10位以内的数字',
  96. // }
  97. // ]
  98. // },
  99. // // 对collect_number字段进行必填验证
  100. // collect_number: {
  101. // rules: [{
  102. // required: true,
  103. // errorMessage: '10位以内的数字',
  104. // },
  105. // {
  106. // minLength: 1,
  107. // maxLength: 10,
  108. // errorMessage: '10位以内的数字',
  109. // }
  110. // ]
  111. // },
  112. // // 对comment_number字段进行必填验证
  113. // comment_number: {
  114. // rules: [{
  115. // required: true,
  116. // errorMessage: '10位以内的数字',
  117. // },
  118. // {
  119. // minLength: 1,
  120. // maxLength: 10,
  121. // errorMessage: '10位以内的数字',
  122. // }
  123. // ]
  124. // }
  125. // },
  126. mysNavConfig: {
  127. /* 开启单页显示首页图标 */
  128. isHome: true,
  129. /* 固定导航 */
  130. navFixed: true,
  131. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  132. navTitle: {
  133. text: "上传链接",
  134. color: "",
  135. fontSize: "32rpx", // px upx rpx
  136. fontWeight: "normal", // 100 - 700
  137. },
  138. btnType: "type2",
  139. onLeftClick: '',
  140. /* type2 按钮 */
  141. type2Config: {
  142. // 左图标
  143. leftPath: "/static/img/png2.png",
  144. // 右图标
  145. rightPath: "/static/img/png4.png",
  146. // 圆角
  147. radius: "40rpx",
  148. },
  149. },
  150. }
  151. },
  152. onLoad(options) {
  153. let data = options.textObj.replace(/""/g, "");
  154. data = JSON.parse(decodeURIComponent(data))
  155. this.taskId = data.taskId
  156. this.dataStatus = data.dataStatus
  157. this.getData()
  158. },
  159. methods: {
  160. getData() {
  161. this.$https.get('/youngee/c/t/g/get-unsubmit-task-data' +
  162. "?" +
  163. "task_id" +
  164. "=" +
  165. this.taskId)
  166. .then(res => {
  167. console.log(res)
  168. if (res.data.data != null) {
  169. this.formData.play_number = res.data.data.play_number
  170. this.formData.like_number = res.data.data.like_number
  171. this.formData.collect_number = res.data.data.collect_number
  172. this.formData.comment_number = res.data.data.comment_number
  173. this.imageData.push(res.data.data.photo_url)
  174. }
  175. })
  176. },
  177. toRecord() {
  178. var data = {
  179. taskId: this.taskId,
  180. };
  181. data = JSON.stringify(data)
  182. uni.navigateTo({
  183. url: '/pages/workspace/datarecord?textObj=' + encodeURIComponent(data)
  184. });
  185. },
  186. submit() {
  187. // 校验
  188. if (this.formData.play_number == "" || this.formData.like_number == "" || this.formData.collect_number ==
  189. "" || this.formData.comment_number == "") {
  190. uni.showToast({
  191. title: '请输入10位以内的数字',
  192. icon: 'none'
  193. })
  194. return
  195. }
  196. if (this.imageData.length == 0) {
  197. uni.showToast({
  198. title: "请上传正确的截图",
  199. icon: 'none'
  200. })
  201. return
  202. }
  203. // 调用添加链接接口
  204. this.$https.post('/youngee/c/t/p/add-task-data', {
  205. task_id: this.taskId,
  206. play_number: this.formData.play_number,
  207. like_number: this.formData.like_number,
  208. collect_number: this.formData.collect_number,
  209. comment_number: this.formData.comment_number,
  210. photo_url: this.imageData[0],
  211. })
  212. .then(res => {
  213. console.log(res)
  214. uni.navigateBack()
  215. })
  216. },
  217. ceshiChooseSuccess1(tempFilePaths, e) { //选择图片返回
  218. console.log('ceshiChooseSuccess', tempFilePaths, e);
  219. if (e == 0) {
  220. this.store = 'talent_upload/' + this.guid() + '.png'
  221. } else if (e == 1) {
  222. this.store = 'talent_upload/' + this.guid() + '.mp4'
  223. }
  224. /****************
  225. 以下代码是自定义上传逻辑,仅供参考
  226. ***************/
  227. this.imgUpload1(tempFilePaths);
  228. /*******************************/
  229. console.log("imgdata" + this.imageData)
  230. },
  231. imgUpload1(tempFilePaths) {
  232. let that = this
  233. console.log('imgUpload', tempFilePaths)
  234. let config = {
  235. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  236. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  237. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  238. };
  239. let fileName = this.store; //指定上传到OBS桶中的对象名
  240. // let fileName = "talent_upload/icon-arrow-right.png"
  241. let OBSPolicy = { //设定policy内容
  242. "expiration": "2089-12-31T12:00:00.000Z",
  243. "conditions": [{
  244. "bucket": "horastar"
  245. }, //Bucket name
  246. // {"bucket": "goin"},
  247. {
  248. 'key': fileName
  249. }
  250. ]
  251. }
  252. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  253. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  254. uni.uploadFile({
  255. //url: config.EndPoint,
  256. url: config.EndPoint,
  257. filePath: tempFilePaths[0],
  258. name: 'file',
  259. formData: {
  260. 'AccessKeyID': config.AccessKeyId,
  261. 'policy': policyEncoded,
  262. 'signature': signature,
  263. 'key': fileName,
  264. },
  265. success: function(res) {
  266. console.log(res.statusCode); //打印响应状态码
  267. if (res.statusCode == '204') {
  268. that.imageData.push(config.EndPoint + '/' + fileName);
  269. console.log('上传图片成功', res)
  270. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  271. console.log(obs_url)
  272. // that.formData.home_img = obs_url
  273. uni.showToast({
  274. title: '上传成功',
  275. icon: '成功'
  276. });
  277. } else {
  278. console.log('上传图片失败', res)
  279. uni.showToast({
  280. title: '上传失败',
  281. icon: '失败'
  282. });
  283. }
  284. },
  285. fail: function(e) {
  286. console.log(e);
  287. uni.showToast({
  288. title: '上传失败22222',
  289. icon: '失败'
  290. });
  291. }
  292. })
  293. },
  294. guid() {
  295. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  296. var r = Math.random() * 16 | 0,
  297. v = c == 'x' ? r : (r & 0x3 | 0x8);
  298. return v.toString(16);
  299. });
  300. },
  301. }
  302. }
  303. </script>
  304. <style lang="scss" scoped>
  305. .signup {
  306. box-shadow: 0rpx 5rpx 40rpx #ccc;
  307. width: 100%;
  308. position: fixed;
  309. bottom: 0rpx;
  310. display: flex;
  311. height: 90rpx;
  312. padding-top: 2%;
  313. background-color: #FFFFFF;
  314. }
  315. .but1 {
  316. width: 60%;
  317. background-color: #f2d22d;
  318. border-radius: 20rpx;
  319. font-size: 36rpx;
  320. line-height: 200%;
  321. letter-spacing: 10rpx;
  322. font-weight: 500;
  323. height: 80%;
  324. &.on {
  325. background-color: #C0C0C0;
  326. }
  327. }
  328. </style>